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();
});