bare-assert
Assertion library for JavaScript
Documented against
v1.2.0stable
bare-assert — Assertion library for JavaScript.
Mirrors the Node.js assert module.
npm i bare-assertUsage
const assert = require('bare-assert')
assert(1 + 1 === 2, 'sum should be correct')
assert.equal(1, 1)
assert.notEqual(1, 2)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
| 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
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
| 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).
assert.doesNotMatch(actual: string, expected: RegExp, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | string | — | — |
expected | RegExp | — | — |
message? | string | Error | — | — |
assert.equal(actual: any, expected: any, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | any | — | — |
expected | any | — | — |
message? | string | Error | — | — |
assert.ifError(actual: any): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | any | — | — |
assert.match(actual: string, expected: RegExp, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | string | — | — |
expected | RegExp | — | — |
message? | string | Error | — | — |
assert.notEqual(actual: any, expected: any, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | any | — | — |
expected | any | — | — |
message? | string | Error | — | — |
assert.notStrictEqual(actual: any, expected: any, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | any | — | — |
expected | any | — | — |
message? | string | Error | — | — |
assert.ok(value: any, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | any | — | — |
message? | string | Error | — | — |
assert.strictEqual(actual: any, expected: any, message?: string | Error): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
actual | any | — | — |
expected | any | — | — |
message? | string | Error | — | — |
See also
- Builds on
bare-inspect. - Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.