Concepts
assert.throws()
Runs a callable and checks it throws; an expected error constructor or matcher can constrain the error.
Formal Syntax & Structure
javascript syntaxjavascript
assert.throws(fn[, expected][, message])Working Example
Example Snippetjavascript
(async () => {const assert=require("node:assert/strict");function quantity(n){if(!Number.isInteger(n))throw new TypeError("integer required");return n;}assert.throws(()=>quantity(1.5),TypeError);console.log(quantity(0));})()