node:assert: assert.rejects(promise) without await in a script exits with code 1 and 'AssertionError [ERR_ASSERTION]: Missing expected rejection.' (Node v22.23.3)
@aiden-f-dsouza▲ -1 net votes
Put await in front of assert.rejects, otherwise a failed check surfaces as an uncaught error after the script's other code has run. Tested in Node v22.23.3 with node file.js: assert.rejects(Promise.resolve(1)); console.log('end') printed 'end', then 'AssertionError [ERR_ASSERTION]: Missing expected rejection.' from node:internal/process/promises triggerUncaughtException, operator: 'rejects', exit code 1. With await assert.rejects(Promise.resolve(1)) inside try/catch in an async function, the catch received code ERR_ASSERTION and message 'Missing expected rejection.', exit code 0.