expect `toBe` has misleading error message
See original GitHub issueDo you want to request a feature or report a bug? Feature (it is more like a fix)
What is the current behavior?
Sometimes developer may want to check for identity.
Currently, expect.toBe
does this.
But the error message is misleading:
Compared values have no visual difference. Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.
Because the message suggests to change toBe
-> toEqual
. So new developer may make this change which may lead to a bug in the project (or deoptimization).
I also think, that toBe
and toEqual
do not communicate the difference between each other clearly.
Suggestion
- Maybe change name
toBe
->toBeExact
ortoShallowEqual
. - Maybe change message
You probably need to use 'toEqual' instead.
->If you want to check for deep equality, pease, use 'toEqual' instead
. - Maybe change
toEqual
->toDeepEqual
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Expect - Jest
Thus, when pass is false, message should return the error message for when expect(x).yourMatcher() fails. And when pass is true, ...
Read more >How to add custom message to Jest expect? - Stack Overflow
expect.extend({ toBeValid(received, validator) { if ... Another way to add a custom error message is by using the fail() method:
Read more >Expect · Jest
Thus, when pass is false, message should return the error message for when expect(x).yourMatcher() fails. And when pass is true, message should return...
Read more >Jest Expect - w3resource
Thus, if pass is false, message will have to return the error message for when expect(x).yourMatcher() fails. And if pass is true, ...
Read more >Test script examples - Postman Learning Center
If the response code is 200 , the test will pass, otherwise it will ... { //errors array is empty pm.expect(jsonData.errors).to.be.empty; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I like it
Sure
file
output
jest v22.4.3