no-assert-throws-async
July 2, 2026 ยท View on GitHub
๐ Disallow passing an async function to assert.throws()/assert.doesNotThrow().
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ก This rule is manually fixable by editor suggestions.
assert.throws() and assert.doesNotThrow() only catch errors thrown synchronously. An async function never throws synchronously: calling it returns a promise that rejects. So assert.throws(async () => { โฆ }) runs the function, gets back a (rejected) promise, sees no synchronous exception, and fails with a "missing expected exception" error regardless of what the function does. The asynchronous counterparts assert.rejects() and assert.doesNotReject() are the correct choice, and their result must be awaited (see no-unawaited-rejects).
This rule reports assert.throws() / assert.doesNotThrow() calls whose first argument is an async function expression. It offers a suggestion to switch to the async equivalent, adding await when the call is a bare statement inside an async function.
Only inline async function expressions are detected. A non-async function that returns a promise is not flagged, since that cannot be determined statically.
| Method | Replacement |
|---|---|
throws | rejects |
doesNotThrow | doesNotReject |
Examples
import test from 'node:test';
import assert from 'node:assert';
test('rejects', async () => {
// โ
assert.throws(async () => {
await failingOperation();
}, /boom/);
// โ
await assert.rejects(async () => {
await failingOperation();
}, /boom/);
});