-
-
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: clarify errors with .not and equal Expected and Received #7795
Conversation
Thank you for moving forward when I was stuck :) Here are some questions that have been in my mind:
I am working on some pictures of an alternative pattern that we can compare and contrast. |
Here are pictures of a pattern for y’all to discuss:
Current or near future baseline is at left and improved is at right.
|
Here are pictures of a pattern for numeric matchers to include in label for expected value either:
Current or near future baseline is at left and improved is at right.
Although I didn’t (yet) provide picture of equal expected and received, this pattern might make it look less weird. |
I had the same idea about showing I love the For the ones where Expected and Received are the same ( To answer your question
Omitting it completely would make it worse IMO, I think avoiding duplication with Received (as was the goal with my implementation) is a good intermediate route With almost all of them, getting the phrasing right is hard - trade-offs between being concise vs. fluent/correct English. On your question
I'm not sure, what information would you consider useful in the two cases respectively? |
You should definitely make some PRs with your number, match/pattern and asymmetric matcher improvements. About |
Good question, what did I mean? When a test fails, we need useful information to decide:
I agree with your first comment that With an
It seems like
Can we prototype some potential solutions which display:
My gut feeling is when a report provides additional useful information about received value, to omit the directly redundant received value is an alternative to consider. For example, if
For a test like Thanks for your patience with my slow cooker brain. If I sound stubborn, please forgive me. |
For
|
So the pattern you're suggesting would be:
And you're looking for a concise phrasing for the Received line? |
Yes, can we follow that path of prototyping for a while and then weigh the pros and cons? |
I am thankful that you saw problem with reports for |
Can you proposed some phrasing patterns about received value for matchers:
In preceding negative matchers, when serializations of expected and received are not equal, then report can display expected and received values. When we have a pattern that scales to the variety of Jest matchers (and community matchers, for bonus points :) then we can move forward with several small and independent pull requests. Current report seems okay:
Proposed improvement seems okay:
|
I'll list a few options with their downsides. Not sure we'll find something that does not allow for any complaints, but maybe something with only downsides we can live with.
(Current message)
(My initial proposal)
(Your initial proposal)
Something after the colon that is not the printed value, might not be a problem because the color highlighting still distinguishes the printed value?
Messy (+problem of the one above), but on the other hand more in line with the proposed number matchers
Sounds like "unexpected token", not clear what was expected instead.
Does not work well with "Not expected value", "Not expected length", ...
Long
Hard to read depending on value, conflates |
Bravo! Do you also have any ideas for phrasing pattern when received value is referential or deep equal to (not) expected value? |
Closing in favor of Mark's PRs |
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
Currently, errors generated using matchers with
.not
mostly only show the fact thatnot
is being used in theexpect(received).not.toEqual(expected)
pseudocode. This leads to (IMO) confusing errors like:My idea is to replace the
Expected: 42
with what the matcher really expects in this case: Anything other than 42.Expected and Received are swapped so that "anything else" comes after "42"
The concrete phrasing may be subject to debate ofc, not sure about the "length" and "thrown substring" ones.
Would love to hear what @pedrottimark in particular thinks about this way of handling
.not
matchers.Note: There are matchers that can cause Expected and Received to be the same without using
.not
, e.g.toBeGreaterThan
. I also find errors from those somewhat weird, but did not touch them for this PR.Test plan
Updated snapshots