Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/unitest/matcher/to_throw.ts>toThrow

๐Ÿƒ Deno-first universal unit testing framework
Latest
function toThrow
import { toThrow } from "https://deno.land/x/unitest@v1.0.0-beta.82/matcher/to_throw.ts";

Use .toThrow to test that a function throws when it is called

import { expect, test } from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("passes when the function throw error", () => {
  expect(() => {
    throw Error("test");
  }).toThrow(/test/);
});

Parameters

actual: AnyFn
optional
expected: string | RegExp