node:assert API Reference

Node-compatible assertion helpers

The module export is callable and is the same function as assert.ok:

import assert from "node:assert";

assert(1 + 1 === 2);
assert.strictEqual(1 + 1, 2);
assert.deepStrictEqual({ values: [1, 2] }, { values: [1, 2] });
await assert.rejects(async () => {
  throw new TypeError("nope");
}, TypeError);

Operations

Supported assertions include:

  • ok, fail, and ifError
  • equal, notEqual, strictEqual, and notStrictEqual
  • deepEqual, notDeepEqual, deepStrictEqual, notDeepStrictEqual, and partialDeepStrictEqual
  • throws, doesNotThrow, rejects, and doesNotReject
  • match and doesNotMatch

assert.strict is a callable strict-mode variant. Deep comparison supports cycles and common built-ins such as arrays, typed arrays, dates, regular expressions, maps, and sets.

Failed assertions throw assert.AssertionError with code set to ERR_ASSERTION and fields including actual, expected, and operator. Elide 1.5.0 reports operation names such as strictEqual in operator, rather than symbols such as ===.

See the Node.js assert documentation for the standard calling forms.