Skip to main content
Module

x/unitest/mod.ts>toBeError

🃏 Deno-first universal unit testing framework
Latest
function toBeError
import { toBeError } from "https://deno.land/x/unitest@v1.0.0-beta.82/mod.ts";

Use .toBeError when checking if a value is Error object or Error extended object.

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

const expect = defineExpect({
  matcherMap: {
    toBeError,
  },
  modifierMap: {
    not,
  },
});

test("passes when given an error", () => {
  expect(Error()).toBeError();
  expect({}).not.toBeError();
  expect(TypeError()).toBeError(TypeError);
  expect(TypeError()).not.toBeError(Error);
  expect(TypeError("test with unitest")).toBeError(TypeError, "unitest");
});

Parameters

actual: unknown
optional
ErrorClass: new (...args: any[]) => Error
optional
messageIncludes: string