question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
richard-lingcommented, Nov 29, 2020

This is awesome and exactly what I’ve been looking for in the docs for the last day. Please merge it soon!

0reactions
github-actions[bot]commented, Apr 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found