bare-assert
Assertion library for JavaScript
stable
Source
Source
Source
Source
Source
bare-assert — Assertion library for JavaScript.
Mirrors the Node.js assert module.
npm i bare-assertAPI
AssertionError
AssertionError
new AssertionError(opts?: {
message?: string
actual?: any
expected?: any
operator?: string
})Create an AssertionError, optionally setting its message, actual, expected, and operator.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
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
| Parameter | Type | Default | Description |
|---|---|---|---|
value | any | — | The value to assert is truthy. |
message? | string | Error | — | Custom message for the thrown error; if an Error instance, it is thrown directly instead of an AssertionError. |
Throws
AssertionError— thrown ifvalueis falsy (unlessmessageis anErrorinstance, which is thrown instead).
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.