-
-
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: Improve report when assertion fails, part 4 #7241
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7241 +/- ##
==========================================
+ Coverage 67.46% 67.48% +0.02%
==========================================
Files 247 247
Lines 9516 9522 +6
Branches 5 5
==========================================
+ Hits 6420 6426 +6
Misses 3094 3094
Partials 2 2
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.
Nice work! I love these little improvements.
I've left some comments regarding the language (should be applied throughout this diff, not only in marked places)
packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap
Outdated
Show resolved
Hide resolved
packages/expect/src/__tests__/__snapshots__/to_throw_matchers.test.js.snap
Outdated
Show resolved
Hide resolved
@pedrottimark Thanks for the good work! From what I've observed so far, the work you've been doing does two things.
I think it would be good to document the standard you have somewhere in the Thoughts @SimenB @mattphillips ? |
Should be added in a readme for https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils and maybe under https://jestjs.io/docs/en/expect#expectextendmatchers Not sure it should be in contributing? |
Just an idea, but what about, instead of Clarity and scannability of the assertion error is very important, IMO. I should be able to at a glance see what I did wrong without having to read to much. |
@thymikee Thank you for review with helpful suggestions:
EDIT 2018-12-12 replaced cannot with must not in 3 messages see #7241 (comment)
|
@SimenB concerning #7241 (comment) yeah, it still feels like room for improvement:
|
@SimenB @thymikee @natealcedo What do you think of more verbose |
Add colors to expected/received and it would be perfect. But I like this proposal as is too :) |
I personally love it! The benefits I see are as follows:
|
@thymikee You mean like this: Although more consistent, I think it’s an example where less color is more clear information hierarchy. |
I like both, so let's keep what we have now. Thanks for showing that! :) |
I think the |
Picture of additional improvements, except that matcher name in regular font weight waits for future pull request: |
Could you update the changelog? 🙂 |
Would love for any of @cpojer @rubennorte and @mjesun to chime in on these changes |
I'd love to get this in. @pedrottimark mind rebasing? |
@thymikee Tests passing locally but CI failing. Maybe I messed up merging upstream changes and also your push to my origin (forgot those at first and then forgot to save my edits to resolve conflicts :) |
tests passed but exited with code 1? wtf |
Failed with an obsolete snapshot? EDIT: Ah, that is not visible using the dot reporter. You can see it on appveyor, though @rickhanlonii pls halp |
I love the extra information being provided in these fail reports but, although it's kinda minor, feel there's a failing in the semantics of the newer messages: Given that we write some code along the lines of:
where we previously had a message along the lines of, "Expected X to be Y", we now have a message saying "X must be Y" IMO this breaks the semantics of the testing code and even the implication of the failure message; implying that the result is not just unexpected, but is logically incorrect In plain English this is the equivalent of meeting someone new and saying to them either, "Oh, I expected you to be taller" or, "Oh, you should be taller" |
@borilla Thank you for your thoughts. The phrase “…when assertion fails” in title of this PR might not have clearly communicated that there are only about 10 of these Matcher error reports for expected or received values that are incorrect according to the purpose of the matcher. That is, the assertion fails because the matcher is not written correctly, instead of because the received value does not match the expected criterion. I am happy to receive critique about fluent meaning of words in international technical English :) For example, I consulted https://www.ietf.org/rfc/rfc2119.txt to decide between must and should. While reading the messages again, I see that cannot in one message is not exact opposite of must. @thymikee Does a change to must not help or hurt:
|
@pedrottimark haha I'm not a native English speaker so I'm not a right person to ask :D But according to quick research "must not" seems better here, and it plays well with "must" we use already in other matchers. |
@pedrottimark Thank you very much for taking time to clarify In this case I agree that must and must not are the correct terms. I withdraw my reservations and look forward to the update |
@pedrottimark thanks for your patience, we all love your work on improving UI ❤️ |
* expect: Improve report when assertion fails, part 4 * Added snapshot test for toHaveLength expected length * Fix prettier lint error * Made improvements requested by thymikee * Make improvements suggested by SimenB * Update CHANGELOG.md * Save the change to resolve the other merge conflict * Deleted assertion_counts.test.js.snap * Replace cannot with must not * Fix prettier lint 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
Improve report when matcher throws error:
Expected
was used with received valuesReceived
was used with expected valuesAdded condition
Expected value must be number
totoHaveLength
matcherResidue for future pull request:
toMatchObject
: find and fix pass must be initialized[.not]
with definite presence or absence of.not
into_throw_matchers.js
andspy_matchers.js
Test plan
See pictures in following comments but see also improvements in #7241 (comment)