no-assert-throws-call

July 2, 2026 ยท View on GitHub

๐Ÿ“ Disallow calling the function passed to assert.throws().

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

๐Ÿ’ก This rule is manually fixable by editor suggestions.

assert.throws() must receive a function that it can call and catch. Passing the result of a call, like assert.throws(parse(input)), runs parse(input) before assert.throws() starts. If that call throws, the error escapes the assertion entirely.

This rule reports direct calls passed as the first argument to assert.throws(). Calls that obviously produce functions, like .bind() and Function(), are ignored. Other function factories are intentionally not guessed; if a factory call is valid in your test, assign the factory result to a variable before passing it or disable the rule for that line.

Examples

import assert from 'node:assert';

// โŒ
assert.throws(parse(input), SyntaxError);

// โœ…
assert.throws(() => parse(input), SyntaxError);