Skip to main content
assert - Node documentation

Usage in Deno

import * as mod from "node:assert";

The node:assert module provides a set of assertion functions for verifying invariants.

Classes

c
assert.AssertionError

Indicates the failure of an assertion. All errors thrown by the node:assert module will be instances of the AssertionError class.

c
assert.CallTracker

This feature is deprecated and will be removed in a future version.Please consider using alternatives such as the mock helper function.

Functions

f
N
assert

An alias of ok.

f
assert.deepEqual

Strict assertion mode

f
assert.deepStrictEqual

Tests for deep equality between the actual and expected parameters."Deep" equality means that the enumerable "own" properties of child objectsare recursively evaluated also by the following rules.

f
assert.doesNotMatch

Expects the string input not to match the regular expression.

f
assert.doesNotReject

Awaits the asyncFn promise or, if asyncFn is a function, immediatelycalls the function and awaits the returned promise to complete. It will thencheck that the promise is not rejected.

f
assert.doesNotThrow

Asserts that the function fn does not throw an error.

f
assert.equal

Strict assertion mode

f
assert.fail

Throws an AssertionError with the provided error message or a defaulterror message. If the message parameter is an instance of an Error thenit will be thrown instead of the AssertionError.

f
assert.ifError

Throws value if value is not undefined or null. This is useful whentesting the error argument in callbacks. The stack trace contains all framesfrom the error passed to ifError() including the potential new frames for ifError() itself.

f
assert.match

Expects the string input to match the regular expression.

f
assert.notDeepEqual

Strict assertion mode

f
assert.notDeepStrictEqual

Tests for deep strict inequality. Opposite of deepStrictEqual.

f
assert.notEqual

Strict assertion mode

f
assert.notStrictEqual

Tests strict inequality between the actual and expected parameters asdetermined by Object.is().

f
assert.ok

Tests if value is truthy. It is equivalent to assert.equal(!!value, true, message).

f
assert.rejects

Awaits the asyncFn promise or, if asyncFn is a function, immediatelycalls the function and awaits the returned promise to complete. It will thencheck that the promise is rejected.

f
assert.strictEqual

Tests strict equality between the actual and expected parameters asdetermined by Object.is().

f
assert.throws

Expects the function fn to throw an error.

Interfaces

I
assert.CallTrackerCall
No documentation available
I
assert.CallTrackerReportInformation
No documentation available

Namespaces

N
v
assert.strict

In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example,deepEqual will behave like deepStrictEqual.

Type Aliases

T
assert.AssertPredicate
No documentation available
T
assert.strict.AssertionError
No documentation available
T
assert.strict.AssertPredicate
No documentation available
T
assert.strict.CallTrackerCall
No documentation available
T
assert.strict.CallTrackerReportInformation
No documentation available