no-assert-throws-multiple-statements

July 3, 2026 Β· View on GitHub

πŸ“ Disallow multiple statements in assert.throws()/assert.rejects() callbacks.

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

assert.throws() and assert.rejects() pass when their callback throws or rejects with the expected error. If the callback also performs setup work, a setup error can satisfy the assertion before the code under test runs.

Keep the callback focused on the single operation expected to fail. Move setup outside the assertion.

This rule reports inline throws() and rejects() callbacks resolved from node:assert, including named imports, strict namespace forms, optional member calls, and t.assert from node:test. It intentionally does not inspect callback identifiers, computed assertion calls, or nested blocks.

Examples

import assert from 'node:assert';

// ❌
assert.throws(() => {
	setup();
	run();
});

// βœ…
setup();
assert.throws(() => run());

// βœ…
setup();
assert.throws(() => {
	run();
});