assertStrict
Prefer strict assertion mode from Node.js for better error messages and behavior.
✅ This rule is included in the node logical presets.
In strict assertion mode, non-strict methods like deepEqual() behave like their strict counterparts (deepStrictEqual()).
Strict mode provides better error messages with diffs and more reliable equality checks, reducing the risk of false positives in tests.
Examples
Section titled “Examples”import function assert(value: unknown, message?: string | Error): asserts value
An alias of
assert.ok
.
assert from "assert";
import function assert(value: unknown, message?: string | Error): asserts value
An alias of
assert.ok
.
assert from "node:assert";
import { function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void
Strict assertion mode
An alias of
deepStrictEqual
.
Legacy assertion mode
Stability: 3 - Legacy: Use
deepStrictEqual
instead.
Tests for deep equality between the actual and expected parameters. Consider
using
deepStrictEqual
instead.
deepEqual
can have
surprising results.
Deep equality means that the enumerable "own" properties of child objects
are also recursively evaluated by the following rules.
deepEqual } from "node:assert";import function assert(value: unknown, message?: string | Error): asserts value
assert from "assert/strict";
import function assert(value: unknown, message?: string | Error): asserts value
assert from "node:assert/strict";
import { function assert.strict(value: unknown, message?: string | Error): asserts valuenamespace assert.strictexport assert.strict
strict as function assert(value: unknown, message?: string | Error): asserts value
assert } from "node:assert";
import { function strict(value: unknown, message?: string | Error): asserts value
strict } from "node:assert";Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you specifically need the non-strict behavior of assertion methods (for example, when testing legacy code that relies on coercive equality), you might choose not to enable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useNodeAssertStrict