-
-
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: Replace shallow equality with referential identity in ExpectAPI.md
#6991
Conversation
@@ -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). |
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.
Please take into account that shallow comparison of objects usually compares their properties, not their identity, thus it's not correct in this case.
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.
yeah, maybe we should have "also known as referential identity"?
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 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: |
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.
Same here about .toBe
and shallow equality.
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.
@rubennorte Yes, what do you think of object identity instead in this sentence?
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.
It's not just objects so I'd use "strict equality" here o "referential identity" as Simen said.
ExpectAPI.md
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. |
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
Better safe than sorry, especially because I missed additions for
.toBe
in 22.2Test plan
yarn lint:md
which I should have done in the first place ;)