Optional
errorClassOrMsg: string | (new (...args) => E)Optional
msgIncludesOrMsg: stringOptional
msg: string24.7.0
import { assertThrows } from "assert";
assertThrows(() => { throw new TypeError("hello world!"); }, TypeError); // Doesn't throw
assertThrows(() => { throw new TypeError("hello world!"); }, RangeError); // Throws
Executes a function, expecting it to throw. If it does not, then it throws. An error class and a string that should be included in the error message can also be asserted.
To assert that an asynchronous function rejects, use assertRejects.