LogoPear Docs
ReferencesBareModules

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

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

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

The actual value that failed the assertion.

expected: any

The expected value the assertion was checked against.

operator: string

The comparison operator used by the assertion that failed, for example '==' or 'strictEqual'.

Functions

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

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