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