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: Replace shallow equality with referential identity in ExpectAPI.md #6991

Merged
merged 3 commits into from
Sep 19, 2018

Conversation

pedrottimark
Copy link
Contributor

Summary

Better safe than sorry, especially because I missed additions for .toBe in 22.2

Test plan

yarn lint:md which I should have done in the first place ;)

@@ -366,7 +366,7 @@ test('rejects to octopus', async () => {

### `.toBe(value)`

`toBe` just checks that a value is what you expect. It uses `Object.is` to check exact equality.
Use `.toBe` to compare primitive values or to check identity of object instances (also known as "shallow" equality).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take into account that shallow comparison of objects usually compares their properties, not their identity, thus it's not correct in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, maybe we should have "also known as referential identity"?

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 indeed, thank you, will fix it.

Don't use `toBe` with floating-point numbers. For example, due to rounding, in JavaScript `0.2 + 0.1` is not strictly equal to `0.3`. If you have floating point numbers, try `.toBeCloseTo` instead.
Don't use `.toBe` with floating-point numbers. For example, due to rounding, in JavaScript `0.2 + 0.1` is not strictly equal to `0.3`. If you have floating point numbers, try `.toBeCloseTo` instead.

Although the `.toBe` matcher **checks** shallow equality, it **reports** a deep comparison of values if the assertion fails. 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, to assert whether or not elements are the same instance:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about .toBe and shallow equality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubennorte Yes, what do you think of object identity instead in this sentence?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just objects so I'd use "strict equality" here o "referential identity" as Simen said.

@SimenB SimenB changed the title docs: Correct CHANGELOG.ms and ExpectAPI.md in 22.2 and 23.0 docs: Correct CHANGELOG.md and ExpectAPI.md in 22.2 and 23.0 Sep 17, 2018
@pedrottimark pedrottimark changed the title docs: Correct CHANGELOG.md and ExpectAPI.md in 22.2 and 23.0 docs: Replace shallow equality with referential identity in ExpectAPI.md Sep 17, 2018
@pedrottimark
Copy link
Contributor Author

See what y’all think about the changes. Making incorrect parallel between terms for copying and terms for comparing seems too familiar. Maybe correcting it 26 times will make it stick for a while.

@SimenB SimenB merged commit 86fc23d into jestjs:master Sep 19, 2018
@pedrottimark pedrottimark deleted the explain-diff-2 branch September 19, 2018 14:30
@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