require-throws-validator-return-true
July 2, 2026 ยท View on GitHub
๐ Require validator functions in assert.throws()/assert.rejects() to return true.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
assert.throws() and assert.rejects() accept a validator function as the error matcher. Node expects that validator to return the boolean value true after its internal checks pass. If the validator returns undefined, a truthy non-boolean value, a Promise, or a generator object, Node throws an AssertionError even when the assertions inside the validator passed. This includes async and generator validator functions.
This rule reports inline validator functions passed to assert.throws()/assert.rejects() when they cannot return true. Referenced validators are ignored.
Examples
import assert from 'node:assert/strict';
// โ
assert.throws(() => run(), error => {
assert.match(error.message, /bad/);
});
// โ
assert.throws(() => run(), error => {
assert.match(error.message, /bad/);
return true;
});