API reference@evolu/commonAssert › assertThrowsInstanceOf

function assertThrowsInstanceOf<T>(
  run: () => unknown,
  constructor: T,
): InstanceType<T>;

Defined in: packages/common/src/Assert.ts:466

Asserts that a function throws an instance of a constructor.

Returns the narrowed instance so additional properties can be asserted without running the function again.

Example

import { assertEqual, assertThrowsInstanceOf } from "@evolu/common";

const error = assertThrowsInstanceOf(() => {
  throw new TypeError("Expected a string.");
}, TypeError);
assertEqual(error.message, "Expected a string.");