-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close comparison between float numbers within objects #3654
Comments
Jest already can do that :). See http://facebook.github.io/jest/docs/en/expect.html#tobeclosetonumber-numdigits |
@thymikee it's slightly different from my proposal. The link you provided only does that for a single value, I have an object with lots of properties that contain floats. unpacking each value and testing it would be really laborious. do you think it makes sense? I edited the description to be more specific. Thank you for the answer! |
I don't see the reason we should add this kind of matcher, as this use case is very specific. |
Fair enough. I just have tons of tables with floats because I'm building a UI for charts! I was trying to reuse the jest tooling to create my own matcher via extend but I'd have to copy and paste code or write my own traversal function. I ended up just hardcoding some piece of data in my test so it always generates the same values and then toEqual becomes useful again. Thanks for the response! <o/ |
Also see #4058 |
Nice! Thanks @clawconduce <o/ |
That gets 3000 downloads per week now. Comparing things like three.js vectors and matrices doesn't seem like a "very specific" use case; on the contrary it seems pretty common in graphics. Couldn't this be added to Jest? |
++ because extending expect is horrible in typescript. |
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. |
Do you want to request a feature or report a bug?
Feature request
What is the current behavior?
.toEqual
doesn't provide close comparison between float numbers within objects. I'm aware oftoBeCloseTo
but it's just too much work for me to unpack all the sub (and sub-sub) properties within the object I want to test.What is the expected behavior?
Maybe
.toEqual
could receive another parameter for the precision tolerated by tests, or maybe another explicit matcher like.toEqualWithFloats
could be added.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
That's reproducible with the default jest configuration. I'm using jest v19.0.2.
Test case
The text was updated successfully, but these errors were encountered: