expect: Improve report when matcher fails, part 12#8033
expect: Improve report when matcher fails, part 12#8033SimenB merged 3 commits intojestjs:masterfrom
Conversation
| '\n' | ||
| ); | ||
| } | ||
| } else if (expected !== undefined) { |
There was a problem hiding this comment.
Good question, as usual.
Some expect code tries to avoid instanceof but is it still a problem?
There was a problem hiding this comment.
I think that might be due to e.g. Error being weird across sandbox boundaries. But here we want you to pass something to us that we run.
I confused myself with that sentence 😛 Did it make sense?
There was a problem hiding this comment.
matcher error if not string or regexp? maybe next major
There was a problem hiding this comment.
A place to change in next major is in createMatcher function, replace:
} else if (expected !== null && typeof expected.test === 'function') {
return toThrowExpectedRegExp(matcherName, options, thrown, expected);with
} else if (expected instanceof RegExp) {
return toThrowExpectedRegExp(matcherName, options, thrown, expected);|
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
For
.toThrowand.toThrowErrormatchers:notfollowing expected label===strict equalityResidue
error.nameis not the same aserror.constructor.nameprobably together with.toBeInstanceOfmatcher.execmethod in addition to.testmethod for RegExpFor more information, see discussion with @jeysal in #7795
Test plan
Change error message to more realistic
"Invalid array length"in 6.notsnapshotsChore in snapshot names:
.toThrow()and.toThrowError()withtoThrowandtoThrowErrorstringswithsubstringUpdated existing tests: all 60 names because of chore and snapshots:
See also pictures in following comment.