-
-
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
docs: Explain how to rewrite assertions to avoid large irrelevant diff #6971
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6971 +/- ##
==========================================
+ Coverage 66.9% 66.97% +0.07%
==========================================
Files 250 250
Lines 10424 10381 -43
Branches 4 3 -1
==========================================
- Hits 6974 6953 -21
+ Misses 3449 3427 -22
Partials 1 1
Continue to review full report at Codecov.
|
Ouch, resolved merge conflict but picked up pretty lint error 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.
This is great!
@@ -930,6 +937,11 @@ describe('the La Croix cans on my desk', () => { | |||
|
|||
> Note: `.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors. | |||
|
|||
If differences between properties do not help you to understand why a test fails, especially if the report is large, then you might move the comparison into the `expect` function. For example, use `equals` method of `Buffer` class to assert whether or not buffers contain the same content: | |||
|
|||
- rewrite `expect(received).toEqual(expected)` as `expect(received.equals(expected)).toBe(true)` |
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.
we could potentially suggest custom matchers so they can show the diff they want?
@pedrottimark could you copy the new explanation to the versioned docs as well? https://github.com/facebook/jest/tree/master/website/versioned_docs |
Thank you for clean up :) I omitted the sentences about |
Awesome, hopefully this'll help some folks |
@@ -887,8 +886,7 @@ describe('the La Croix cans on my desk', () => { | |||
}); | |||
``` | |||
|
|||
> Note: `.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors. | |||
If differences between properties do not help you to understand why a test fails, especially if the report is large, then you might move the comparison into the `expect` function. For example, use `equals` method of `Buffer` class to assert whether or not buffers contain the same content: |
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.
@pedrottimark did you mean for these to be on separate paragraphs? If so, there has to be 2 newlines, as MD collapses them (to allow you to write e.g. max 80 chars wide, but still render as a single paragraph without any weird newlines)
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.
Yes, my bad. Do you want to push a commit or have me submit follow up pull request to provide missing blank lines.
Also, notice duplicate Chore & Maintenance
heading in CHANGELOG.md
file.
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.
Feel free to fix and just push to master 🙂
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
“If differences between properties do not help you to understand why a test fails, especially if the report is large, then you might move the comparison into the
expect
function.”While we are at it, make leading sentence about
.toBe
and.toEqual
parallel:Test plan
Review by human, and thank you for it <3