-
-
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
Share more logic between object equality and arrays #11061
Conversation
Just in case: I double-checked locally and confirm that the tests added by this PR were green before the code change and are still green now. By adding them, I wanted to make sure I did not change how Jest considered sparse arrays equality. |
<g>- Expected - 1</> | ||
<r>+ Received + 1</> |
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.
The Expected / Received seems to be wrong there 🤔
Nonetheless it does not seem related to my change as I got the same snapshot before my dev.
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.
wrong how? they reflect the +
and -
in the diff below, no?
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.
<d> Array [</>
<d> undefined,</>
<d> undefined,</>
<g>- 2,</>
<r>+ 1,</>
<d> undefined,</>
<d> ]</>
It looks that the diff should be:
<g>- Expected - 2</>
<r>+ Received + 1</>
(clearly not sure of me on that one)
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.
ah, I see what you mean. You misunderstand (I think 😛) - the heading is a counter of the number of -
and +
lines, it's not an extracted part of the diff itself
(Object.getOwnPropertySymbols(obj) as Array<any>).filter( | ||
symbol => | ||
(Object.getOwnPropertyDescriptor(obj, symbol) as PropertyDescriptor) | ||
.enumerable, |
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.
thanks prettier
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.
I blame the people who put enumerable symbol-keyed properties on objects in the first place ^^
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.
thanks! would like some extra 👀 on this, although passing tests and less code is always good 🙂
@SimenB By the way I'm working on a PR to have more appropriate snapshots for sparse arrays. I'll certainly have to sync with @pedrottimark regarding that point |
To be clear, this does not (or at least is not expected to) change behavior, before and after this change |
@jeysal I confirm, if I revert my change in |
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.
I trust in our test suite and think this is good to go ^^
@SimenB Do you want me to update the PR? If yes, do you prefer rebase and force push OR merge? |
Sorry, forgot about this one. Just merging in master sounds good to me 🙂 (easier to see changes between pushes when there's no force pushing) |
Codecov Report
@@ Coverage Diff @@
## master #11061 +/- ##
==========================================
- Coverage 64.19% 64.14% -0.05%
==========================================
Files 308 308
Lines 13532 13514 -18
Branches 3299 3293 -6
==========================================
- Hits 8687 8669 -18
Misses 4131 4131
Partials 714 714
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.
very nice!
Thanks a lot 👍 |
Haha, thank you! 😀 This started out for #11055, what's the status with this and the |
I think I still have one part of the code of jest to investigate, but we should be close from the full fix. If I'm not wrong my current fix on I believe the printed value is always computed by expect if I am not wrong 🤔 (even if no error) |
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
While investigating the reasons behind #11055, I found a possible way to factorize the logics of object comparison with array comparison. As it seems to simplify and reduce a bit the amount of code needed, I thought it would be good to let share it with you.
Even if this suggestion clearly enhances the case of the issue #11055, it still does not fully fix it as error message generation seems to still iterate over all the holes (did not impacted it in this PR).
Test plan
Tests have been added for sparse arrays in order to ensure the PR does not introduce unwanted regressions.
As you will see in the snapshots, snapshots for sparse arrays are not perfect as they let users think that the array was full of undefined values. This PR does not try to change this behaviour.