Concepts
assert.rejects()
Awaits a rejected promise and checks the expected error if supplied; the returned promise must be awaited or returned by the test.
Formal Syntax & Structure
javascript syntaxjavascript
await assert.rejects(asyncFnOrPromise[, expected][, message])Working Example
Example Snippetjavascript
(async () => {const assert=require("node:assert/strict");await assert.rejects(async()=>{throw new RangeError("limit");},RangeError);console.log("rejection checked");})()