Skip to content
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

Add type checks for asymmetric matchers #5069

Merged
merged 3 commits into from
Jan 7, 2018

Conversation

rogeliog
Copy link
Contributor

Summary

This PR adds a check to fail when the types of "string" asymmetric matchers do not match cc: @pedrottimark

Fixes: #5021

Test plan

screen shot 2017-12-12 at 10 02 44 am

@codecov-io
Copy link

codecov-io commented Dec 12, 2017

Codecov Report

Merging #5069 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5069   +/-   ##
=======================================
  Coverage   61.18%   61.18%           
=======================================
  Files         202      202           
  Lines        6765     6765           
  Branches        4        3    -1     
=======================================
  Hits         4139     4139           
  Misses       2625     2625           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e776fdd...4d9bb83. Read the comment docs.

@@ -218,6 +222,10 @@ class StringMatching extends AsymmetricMatcher {
}

asymmetricMatch(other: string) {
if (!isA('String', other) && !isA('RegExp', other)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although sample can be either string or regexp, it seems like other can only be a string.

Copy link
Contributor

@pedrottimark pedrottimark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm whether same if condition works for both matchers.

@pedrottimark
Copy link
Contributor

@rogeliog Happy New Year! Thank you, it looks good to me now.

@@ -218,6 +222,10 @@ class StringMatching extends AsymmetricMatcher {
}

asymmetricMatch(other: string) {
if (!isA('String', other)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to our docs, stringMatching() accepts a regexp. Mind changing the type and runtime check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rogeliog can you take a look at this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee The StringMatching constructor does indeed take either string or RegExp, but argument of the asymmetricMatch function takes only string as received value, true?

That is, expect.stringMatching(/^Alic/) returns true when the received value is 'Alicia' or false when the received value is 'Bob' but should report an error if the received value is a RegExp, because how to decide if a received RegExp matches an expected RegExp?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrottimark you're right, I mistaken other with sample

@cpojer cpojer merged commit b86d932 into jestjs:master Jan 7, 2018
@SimenB
Copy link
Member

SimenB commented Jan 7, 2018

*cough*changelog*cough*

rogeliog added a commit to rogeliog/jest that referenced this pull request Jan 8, 2018
@rogeliog
Copy link
Contributor Author

rogeliog commented Jan 8, 2018

@SimenB Thanks! I just created a PR for it #5250

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jest errors out when expecting a mock to be called with a string matcher
7 participants