Skip to content

DanielHreben/jest-matcher-specific-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8007285 · Jan 24, 2024

History

34 Commits
Jan 24, 2024
Jan 24, 2024
Jan 24, 2024
Apr 20, 2020
Oct 5, 2020
Apr 20, 2020
May 26, 2020
Apr 20, 2020
Sep 5, 2023
Oct 5, 2020
Jan 24, 2024
May 29, 2020
Jan 24, 2024

Repository files navigation

jest-matcher-specific-error

Make sure your function really throws what you expect

Workaround for jestjs/jest#8140

Installation

With npm:

npm install --save-dev jest-matcher-specific-error

With yarn:

yarn add -D jest-matcher-specific-error

Setup

Same as Other Jest matchers.

Typescript

Same as Other Jest matchers.

Usage

await expect(yourPromise).rejects.toMatchError(expectedError);
await expect(yourFunction).rejects.toMatchError(expectedError);
expect(yourError).toMatchError(expectedError);

Match logic

Errors threated as equal if ALL conditions satisfied:

  • Errors are instances of same class (strict === comparison by reference)
  • Error messages are equal
  • All error public fields are deeply equal (default jest helper comparison)

Error stack traces are ignored.