Why: The way you write tests in Jasmine and Jest is extremely similar, but the APIs for adding custom matchers vary wildly between Jasmine 1.x, Jasmine 2.x, and Jest. This library aims to remove those obstacles and encourage Developers to share useful matchers they've created with the community.
How: Developers use the API from this library, which converts them to be compatible with whichever test framework is running.
npm install --save-dev add-matchers
Include add-matchers after your test framework but before your tests, and register your matchers before your tests as well.
Add Custom Matchers
Add Custom Asymmetric Matchers
The argument passed to
expect is always the last argument passed to your
Matcher, with any other arguments appearing before it in the order they were
This means that, in the case of
expect(received).toBeAwesome(arg1, arg2, arg3), your function will be called
fn(arg1, arg2, arg3, received).
Arguments are ordered in this way to support partial application and increase re-use of matchers.
If we wanted to use the following Matchers in our tests;
// matcher with 0 arguments; // matcher with 1 argument; // matcher with Many arguments;
We would create them as follows;
For more examples, see Jasmine Matchers which is built using this library.
- Jasmine Matchers: A huge library of test assertion matchers to improve readability.
- karma-benchmark: A Karma plugin to run Benchmark.js over multiple browsers, with CI compatible output.
- karma-jasmine-matchers: A Karma plugin to inject Jasmine Matchers.
Easy to read test output with nested