LogoPear Docs

bare-assert

Assertion library for JavaScript

stable

bare-assert — Assertion library for JavaScript.

Mirrors the Node.js assert module.

npm i bare-assert

API

AssertionError

AssertionError

new AssertionError(opts?: {
      message?: string
      actual?: any
      expected?: any
      operator?: string
    })
Source

Create an AssertionError, optionally setting its message, actual, expected, and operator.

Parameters

ParameterTypeDefaultDescription
opts?{ message?: string actual?: any expected?: any operator?: string }Fields to set on the new error: message (defaults to a generated "<actual> <operator> <expected>" string), actual, expected, and operator.

actual: any

Source

The actual value that failed the assertion.

expected: any

Source

The expected value the assertion was checked against.

operator: string

Source

The comparison operator used by the assertion that failed, e.g. '==' or 'strictEqual'.

Functions

assert(value: any, message?: string | Error): void

Source

Throw an AssertionError if value is falsy.

Parameters

ParameterTypeDefaultDescription
valueanyThe value to assert is truthy.
message?string | ErrorCustom message for the thrown error; if an Error instance, it is thrown directly instead of an AssertionError.

Throws

  • AssertionError — thrown if value is falsy (unless message is an Error instance, which is thrown instead).

See also

On this page