prefer-test-context-assert
July 3, 2026 Β· View on GitHub
π Prefer the test context t.assert over the imported node:assert.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π‘ This rule is manually fixable by editor suggestions.
The test context exposes the node:assert methods as t.assert. Using them instead of the imported node:assert ties each assertion to the running test, which lets the runner count assertions and makes t.plan() work.
This rule reports imported node:assert calls made inside a test whose callback has a context parameter, including strict namespace forms, and suggests the t.assert equivalent. Calls outside a test, in a hook, or in a subtest whose callback takes no context parameter are left alone, since there is no context to convert to.
The suggestion preserves behavior: a loose method imported from node:assert/strict (for example assert.equal) is mapped to its strict counterpart (t.assert.strictEqual), because t.assert exposes the non-strict functions.
Examples
import test from 'node:test';
import assert from 'node:assert/strict';
// β
test('title', t => {
assert.equal(actual, expected);
});
// β
test('title', t => {
t.assert.strictEqual(actual, expected);
});