no-useless-assertion

July 2, 2026 Β· View on GitHub

πŸ“ Disallow assert.doesNotThrow() and assert.doesNotReject().

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

assert.doesNotThrow() and assert.doesNotReject() catch an error only to rethrow it, so they add nothing over just running the code. The Node.js docs say so directly: "Using assert.doesNotThrow() is actually not useful because there is no benefit in catching an error and then rethrowing it." If the code under test throws, the test fails either way β€” but calling it directly gives a clearer stack trace.

This rule reports assert.doesNotThrow() and assert.doesNotReject(). Call the code directly, and add a comment if it helps explain why it must not throw.

Examples

import assert from 'node:assert';

// ❌
assert.doesNotThrow(() => parse(input));
await assert.doesNotReject(() => load(url));

// βœ…
parse(input);
await load(url);