-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Fix for 4286: Compare Maps and Sets by value rather than order #4303
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Nice!! Do you mind removing the |
d'oh! of course :) @cpojer Do you think it's worth separating out
because sets and maps set entries via === strict equality comparison. We'd have to iterate over each set again for every object to find and do a nested comparison. Thoughts? |
Yep, I think that makes sense. Thank you so much for this PR and fixing issues in Jest :) |
Thanks for the fix! |
…s#4303) * Add check for Maps & Sets * check for presence of .size() * exit early if size doesn't equal * replace spread with args array
jestjs#4303 added code to check Set equality in an order-independent way, but applied that logic to all iterable objects. This change limits the scope of the special-case to just Set and Map, and corrects the Map case to test that both keys and values are equal.
jestjs#4303 added code to check Set equality in an order-independent way, but applied that logic to all iterable objects. This change limits the scope of the special-case to just Set and Map, and corrects the Map case to test that both keys and values are equal.
* fix Map equality test #4303 added code to check Set equality in an order-independent way, but applied that logic to all iterable objects. This change limits the scope of the special-case to just Set and Map, and corrects the Map case to test that both keys and values are equal. * use isA instead of instanceof
* fix Map equality test jestjs#4303 added code to check Set equality in an order-independent way, but applied that logic to all iterable objects. This change limits the scope of the special-case to just Set and Map, and corrects the Map case to test that both keys and values are equal. * use isA instead of instanceof
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fix for #4286
Modify
iterableEquality
method so that, if two objects have the same constructor with.size
property (i.e.,Map
andSet
), check if the sizes are same. If not, exit early and return false. If yes, perform a union and if the size is still the same, return true. Otherwise, keep checking for deep equality (cases where the elements contain another object)Test plan
Added test cases to
matchers.test.js