Dev HelpersOpen library
← Back

Assert a rejected promise

Assert a rejected promise in JavaScript.

Open this example in the interactive library

Source code

import assert from "node:assert/strict";
await assert.rejects(async () => {
  throw new TypeError("Invalid input");
}, TypeError);
console.log("Rejection matched");

Sample output

Rejection matched