Make sure your function really throws what you expect
Workaround for jestjs/jest#8140
With npm:
npm install --save-dev jest-matcher-specific-error
With yarn:
yarn add -D jest-matcher-specific-error
Same as Other Jest matchers.
Same as Other Jest matchers.
await expect(yourPromise).rejects.toMatchError(expectedError);
await expect(yourFunction).rejects.toMatchError(expectedError);
expect(yourError).toMatchError(expectedError);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 jesthelper comparison)
Error stack traces are ignored.