You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would also be nice to document how to test for rejection with specific error messages. return expect(foo()).rejects.toEqual('bar'); errors out:
expect(received).toEqual(expected)
Expected value to equal:
"bar"
Received:
[Error: bar]
Difference:
Comparing two different types of values. Expected string but received object.
but the Note at the end of the toEqual(value) docs recommends against using it for Error objects and toEqual can be too strict when ideally you'd check for a Regexp.
The text was updated successfully, but these errors were encountered:
You can use toEqual to test Errors if that works for you.
However what this issue shows is that toMatchObject is not checking if the object is error, which can lead to hard-to-track bugs, like this one.
Example can be shortened to:
test('toMatchObject passes on different Errors',()=>{expect(newError('foo')).toMatchObject(newError('bar'));});
I'll close this and open new issue just for toMatchObject.
This issue 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.
Can't post a repl.it because it doesn't run Jest v20+, so here's the code using Promises and rejecting with Error objects (a recommended pattern).
I would expect the test above to fail.
It would also be nice to document how to test for rejection with specific error messages.
return expect(foo()).rejects.toEqual('bar');
errors out:This works:
but the Note at the end of the toEqual(value) docs recommends against using it for Error objects and
toEqual
can be too strict when ideally you'd check for a Regexp.The text was updated successfully, but these errors were encountered: