Skip to content
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

Merged
merged 10 commits into from
Sep 17, 2018

Conversation

pedrottimark
Copy link
Contributor

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:

  • remove phrase that is considered a put-off: just checks
  • improve grammar because of potential confusion: rather than checking for object identity—this is also known as "deep equal"

Test plan

Review by human, and thank you for it <3

@codecov-io
Copy link

Codecov Report

Merging #6971 into master will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-haste-map/src/haste_fs.js 52% <0%> (-5.15%) ⬇️
packages/jest-haste-map/src/module_map.js 87.5% <0%> (-0.74%) ⬇️
packages/jest-runner/src/test_worker.js 0% <0%> (ø) ⬆️
packages/jest-haste-map/src/crawlers/watchman.js 94.87% <0%> (+0.06%) ⬆️
packages/jest-haste-map/src/index.js 95.72% <0%> (+5.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9822231...bcb4ec8. Read the comment docs.

@pedrottimark
Copy link
Contributor Author

Ouch, resolved merge conflict but picked up pretty lint error in CONTRIBUTING.md from #6967

Copy link
Member

@SimenB SimenB left a 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)`
Copy link
Member

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?

@SimenB
Copy link
Member

SimenB commented Sep 15, 2018

@pedrottimark could you copy the new explanation to the versioned docs as well? https://github.com/facebook/jest/tree/master/website/versioned_docs

@SimenB SimenB merged commit 3dd29cd into jestjs:master Sep 17, 2018
@pedrottimark
Copy link
Contributor Author

Thank you for clean up :)

I omitted the sentences about Object.is from 22.x docs because it was added in 22.4.2

@SimenB
Copy link
Member

SimenB commented Sep 17, 2018

Awesome, hopefully this'll help some folks

@pedrottimark pedrottimark deleted the explain-diff branch September 17, 2018 17:25
@@ -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:
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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 🙂

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants