-
-
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: Return false from asymmetric matchers if received value isn’t string #7107
Conversation
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, I agree this makes sense!
Codecov Report
@@ Coverage Diff @@
## master #7107 +/- ##
==========================================
- Coverage 66.67% 66.66% -0.02%
==========================================
Files 253 253
Lines 10597 10593 -4
Branches 3 4 +1
==========================================
- Hits 7066 7062 -4
Misses 3530 3530
Partials 1 1
Continue to review full report at Codecov.
|
Uh oh, the asymmetry of one matcher with Added failing test |
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.
@pedrottimark mind resolving conflicts? :)
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
Fixes #7055
Problem: Although it seemed to make sense at the time to throw an error if received value isn’t string when asymmetric matcher is value of property in
.toEqual
assertion, it contradicts reasonable expectation in other scenarios:.toBeCalledWith
assertion for polymorphic function can throw even if at least one call has an argument that matchesThe constructors still throw if the expected value has incorrect type.
Solution:
isA('String', other)
into conditional expression of.stringContaining
.stringMatching
because regular expressiontest
method returnsfalse
if argument isn’t stringTest plan
Rewrite 2 tests
'StringContaining throws for non-strings'
as:'StringContaining throws if expected value is not string'
'StringContaining returns false if received value is not string'
(failed before code change)Rewrite 2 tests
'StringNotContaining throws for non-strings'
as:'StringNotContaining throws if expected value is not string'
'StringNotContaining returns true if received value is not string'
(failed before code change)Rewrite 1 test
StringMatching throws for non-strings and non-regexps
as:StringMatching throws if expected value is neither string nor regexp
Rewrite 1 test
'StringMatching throws for non-string actual values'
as:'StringMatching returns false if received value is not string'
(failed before code change)Rewrite 1 test
StringNotMatching throws for non-strings and non-regexps
as:StringNotMatching throws if expected value is neither string nor regexp
Rewrite 1 test
'StringNotMatching throws for non-string actual values'
as:'StringNotMatching returns true if received value is not string'
(failed before code change)