Please add asymmetric matcher `expect.closeTo`
See original GitHub issue🚀 Feature Proposal
There is a matcher toBeCloseTo
that’s super useful to assert floats. But when these floats are inside objects or arrays we can’t use it directly. Therefore it would be useful to have an asymmetric matcher so that we can use toEqual with it, eg:
expect(value).toEqual([
{ start: expect.closeTo(5.3), end: expect.closeTo(5.8) }
]);
It makes sense to be included in Jest core because of the existing matcher toBeCloseTo
, that would be more consistent.
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
Adding asymmetric matcher expect.closeTo #12242 - GitHub
There is a matcher toBeCloseTo that's super useful to assert floats. But when these floats are inside objects or arrays we can't use...
Read more >Expect - Jest
closeTo (number, numDigits?) expect. ... You can use expect.extend to add your own matchers to Jest. ... interface AsymmetricMatchers {
Read more >Include toBeCloseTo in Jest .toMatchObject - Stack Overflow
An asymmetric matcher using the logic from toBeCloseTo can be created like this: const closeTo = (expected, precision = 2) ...
Read more >Practical Guide to Custom Jest Matchers - Redd Developer
Creating a custom matcher. Jest provides the expect.extend() API to implement both custom symmetric and asymmetric matchers. This API accepts an ...
Read more >Making custom Jest assertion matchers in JavaScript and ...
We pass in an object with each matcher function we want to add to expect . So adding our matcher function would look...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is awesome and exactly what I’ve been looking for in the docs for the last day. Please merge it soon!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.