-
-
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
expect: Avoid incorrect difference for subset when toMatchObject fails #9005
expect: Avoid incorrect difference for subset when toMatchObject fails #9005
Conversation
Here is minimal reproduction of reported problem for both only only The example above was correct, but now avoids unnecessary copy of matching subset P.S. change counts would be nice in these side-by-side comparisons, heh? |
Here is demonstration that the difference is correct for array subclass, because even if a copy in unnecessary, the only only |
Codecov Report
@@ Coverage Diff @@
## master #9005 +/- ##
========================================
Coverage ? 63.9%
========================================
Files ? 277
Lines ? 11654
Branches ? 2860
========================================
Hits ? 7448
Misses ? 3576
Partials ? 630
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test names could be a bit clearer IMO, other than that LGTM! :)
(sorry for the review delay)
Co-Authored-By: Tim Seckinger <seckinger.tim@gmail.com>
@jeysal Your critique is worth waiting for, my friend. |
I will merge changes from master to see if #9030 solves |
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
Fixes #8947
When the
getObjectSubset
function copies the relevant subset of object properties recursively, it creates ordinaryObject
instances. If expected and received values are a subclass or typed array, then the type change of the received subset becomes an incorrect change in the difference whentoMatchObject
fails.If corresponding values:
Although the function returns an unnecessary copy for arrays, I left it as is, because the
map
method returns the same array class as the subsetBackground information:
toMatchObject
does not require same type: liketoEqual
and unliketoStrictEqual
Array.isArray
returnsfalse
for typed arraysTest plan
Separate tests for deep equality versus referential identity of returned subset
Add 3 new tests which failed before the code change
See also pictures in following comments: baseline is at left and improved is at right