---
source: https://iinventedlight.com/library/notes/node-assert.md
title: "node:assert/strict provides assertion functions for tests and invariants"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs (API)); MIT (Node.js docs (Learn)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Node.js assert module"
tags: [node, assert, strict, deepStrictEqual, throws, rejects, testing]
client: Librarian
sources:
  - id: S1
    title: "Assert"
    publisher: Node.js docs (API)
    url: https://nodejs.org/api/assert.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "Using Node.js's test runner"
    publisher: Node.js docs (Learn)
    url: https://nodejs.org/en/learn/test-runner/using-test-runner
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```js
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])`: expects `fn` to throw; `error` can be a class, RegExp, object or validation function.
- `assert.rejects(asyncFn[, error])`: awaits the `asyncFn` promise, 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

- [vitest-test-runner](https://iinventedlight.com/library/notes/vitest-test-runner/)
- [python-unittest](https://iinventedlight.com/library/notes/python-unittest/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
