-
-
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
Do not highlight matched asymmetricMatcher in diffs #9257
Conversation
I've only had a chance to glance over this quickly, but it looks like this might actually be a decent workaround that is worth it considering the extra maintenance cost, even though of course in the long run it would still be nice to properly solve all cases with better integration of expect/pretty-format/jest-diff as proposed in the issue threads. |
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.
Exciting! Definitely needs @pedrottimark's review. I agree with @jeysal that this behavior needs to be behind an options, as we've tried to keep jest-diff
relatively decoupled from Jest itself and usable as a generic diffing module. I like how small this change is, though!
We can add |
I suggest
Do you think this would be easily possible? Test cases would be an asymmatcher deeper down the structure, and probably something nested like |
@WeiAnAn Thank you for contributing to Jest! Here are a few first impressions:
Object {
"a": 1,
- "b": 2,
+ "b": 1,
} The Outside the scope of this pull request, we might need to compare it to current utility functions which have some problems with recursive replacements in reports when the following matchers fail:
P.S. to Simen and Tim: Last week I returned to prototyping a future “relevant comparison” diff and this PR reminded me to add asymmetric matchers to the realistic examples :) The Full color at left and simulated protanopia (no red, 1% of males) at right: |
@jeysal Thank you point out the issue of nested object and circular object. I will add these test cases. @pedrottimark Thanks for your review.
Move replacing logic to
I think if user use asymmetricMatcher, it means user only focus on asymmetricMatcher's condition. Object {
"a": Any<Number>(1),
- "b": 2,
+ "b": 1,
}
|
Omg yes having pretty-format serialize a value that represents an asymmatcher with its matched value would be awesome! But we might want to serialize just the asymmatcher for now and do that in a follow up because it can be separated easily and reduces the size of this PR which will probably already get big with more tests and recursion etc. |
@WeiAnAn @jeysal Yes, I agree for this PR, let’s keep the original design to replace received value with serialization of asymmetric matcher. Tim, related to your #9257 (comment) and mine in #9239 (comment)
|
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
This fixes #6184.
My implementation is traverse the expected object. If property is asymmetric matcher, check is matched actual or not, then replace actual property with asymmetric matcher.
Code:
Result:
Test plan
Add tests with different types of asymmetric matchers.