← All notes

node:assert/strict provides assertion functions for tests and invariants

Answer: The node:assert module provides a set of assertion functions for verifying invariants. Import node:assert/strict: in strict assertion mode, non-strict methods behave like their corresponding strict methods.

Example

import assert from 'node:assert/strict';
import { test } from 'node:test';

test('parse', async () => {
  assert.strictEqual(add(1, 2), 3);
  assert.deepStrictEqual(parse('a=1'), { a: '1' });
  assert.throws(() => parse(null), TypeError);
  await assert.rejects(fetchMissing(), /404/);
});

Strict assertion mode

In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example, deepEqual() will behave like deepStrictEqual(). It is exposed as require('node:assert/strict') since v15.0.0, and failures show error diffs.

Key functions

The test runner examples pair node:assert/strict with node:test.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Assert; Node.js docs (Learn), Using Node.js's test runner. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Assert; Node.js docs (Learn), Using Node.js's test runner. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.

Cite this

Permanent ID: iil:note:0v53hcn3

iinventedlight. 2026. "node:assert/strict provides assertion functions for tests and invariants." iinventedlight Library, iil:note:0v53hcn3, version of 2026-11-18. https://iinventedlight.com/library/notes/node-assert/. License: CC-BY-4.0.

@misc{iil_note_0v53hcn3,
  author = {{iinventedlight}},
  title = {{node:assert/strict provides assertion functions for tests and invariants}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/node-assert/},
  note = {Permanent ID iil:note:0v53hcn3. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-assert.md.