require-context-assert-with-plan

July 2, 2026 ยท View on GitHub

๐Ÿ“ Require assertions to use the test context when the test sets a plan.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

The test context's plan() method declares how many assertions and subtests a test expects to run. Only assertions made through the test context (t.assert.*) and subtests are counted toward the plan. Assertions from the separately-imported node:assert module are invisible to the runner, so they do not count, and the test fails with a plan mismatch (plan expected N assertions but received fewer).

This rule reports imported node:assert assertions (namespace, named, or bare assert()) inside any test that calls plan(). Switch them to the test context's t.assert so they count. See also prefer-test-context-assert, which can perform that conversion.

Examples

import test from 'node:test';
import assert from 'node:assert';

test('plan', t => {
	t.plan(1);

	// โŒ โ€” not counted, the test fails with a plan mismatch
	assert.strictEqual(actual, expected);

	// โœ… โ€” counted toward the plan
	t.assert.strictEqual(actual, expected);
});