-
-
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
expect: Improve report when matcher fails, part 12 #8033
Conversation
'\n' | ||
); | ||
} | ||
} else if (expected !== undefined) { |
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.
instanceof RegExp
?
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.
Good question, as usual.
Some expect
code tries to avoid instanceof
but is it still a problem?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matcher error if not string
or regexp
? maybe next major
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.
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);
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.
nice work, LGTM 👍
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
.toThrow
and.toThrowError
matchers:not
following expected label===
strict equalityResidue
error.name
is not the same aserror.constructor.name
probably together with.toBeInstanceOf
matcher.exec
method in addition to.test
method for RegExpFor more information, see discussion with @jeysal in #7795
Test plan
Change error message to more realistic
"Invalid array length"
in 6.not
snapshotsChore in snapshot names:
.toThrow()
and.toThrowError()
withtoThrow
andtoThrowError
strings
withsubstring
Updated existing tests: all 60 names because of chore and snapshots:
See also pictures in following comment.