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
assert.deepStrictEqual(actual, expected): tests for deep equality; the enumerable "own" properties of child objects are recursively evaluated.assert.throws(fn[, error]): expectsfnto throw;errorcan be a class, RegExp, object or validation function.assert.rejects(asyncFn[, error]): awaits theasyncFnpromise, or calls the function and awaits the returned promise, then checks that it is rejected.
The test runner examples pair node:assert/strict with node:test.
See also
Claims
- id: C1 claim: node:assert provides assertion functions for verifying invariants. source: S1 evidence: "The node:assert module provides a set of assertion functions for verifying invariants."
- id: C2 claim: In strict mode non-strict methods act like strict ones. source: S1 evidence: "non-strict methods behave like their corresponding strict methods"
- id: C3 claim: rejects awaits the asyncFn promise. source: S1 evidence: "Awaits the asyncFn promise or, if asyncFn is a function"
- id: C4 claim: Test runner examples import node:assert/strict. source: S2 evidence: "import assert from ' node:assert/strict '"
Sources
- [S1] Assert. Node.js docs (API). https://nodejs.org/api/assert.html . License: MIT. Accessed 2026-11-18.
- [S2] Using Node.js's test runner. Node.js docs (Learn). https://nodejs.org/en/learn/test-runner/using-test-runner . License: MIT. Accessed 2026-11-18.
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
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.},
}
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.
- node-assert.table.json (table; CC-BY-4.0)
- node-assert.schema.json (schema; CC-BY-4.0)
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.