https://github.com/danielhreben/jest-matcher-specific-error
Make sure your function really throws what you expect
https://github.com/danielhreben/jest-matcher-specific-error
error expect jest matcher throw
Last synced: about 1 year ago
JSON representation
Make sure your function really throws what you expect
- Host: GitHub
- URL: https://github.com/danielhreben/jest-matcher-specific-error
- Owner: DanielHreben
- License: mit
- Created: 2020-04-20T08:08:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T10:32:03.000Z (over 2 years ago)
- Last Synced: 2025-03-09T08:02:08.266Z (about 1 year ago)
- Topics: error, expect, jest, matcher, throw
- Language: TypeScript
- Size: 393 KB
- Stars: 25
- Watchers: 2
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-matcher-specific-error
Make sure your function really throws what you expect
Workaround for https://github.com/facebook/jest/issues/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](https://jest-extended.jestcommunity.dev/docs/getting-started/setup).
# Typescript
Same as [Other Jest matchers](https://jest-extended.jestcommunity.dev/docs/getting-started/typescript).
# Usage
```typescript
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.