method Assert.prototype.throws
Assert.prototype.throws(
blockFn: unknown,
expectedInput?: unknown,
assertionMessage?: string
): void

Asserts that blockFn throws an exception. Optionally validates the thrown error against a string (message substring), RegExp (message pattern), or constructor (instanceof check). For async functions use Assert.prototype.rejects.

Examples

Example 1

assert.throws(() => { throw new Error("boom"); });
assert.throws(() => JSON.parse("{bad}"), SyntaxError);
assert.throws(() => { throw new Error("bad input"); }, /bad input/);

Parameters

blockFn: unknown

A synchronous function expected to throw.

optional
expectedInput: unknown
optional
assertionMessage: string

Return Type

void

Usage

import { Assert } from ".";