[expect] Fix .any()
checks on primitive wrapper classes
#11976
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently, the
.any()
matcher correctly detects instances of the wrapper classes for numbers and strings:which makes those tests equivalent to the following
instanceof
tests (which they should be):At the moment, though, the same cannot be said for instances of the wrapper classes for booleans, symbols, and bigints (even though the corresponding
instanceof
tests correctly pass):(Note: The
Object(...)
syntax is necessary because neither symbols nor bigints are constructible, and therefore don't work with thenew
keyword.)This is because in the
any()
matcher, there areinstanceof
checks for strings and numbers, but not the other primitives: https://github.com/facebook/jest/blob/a1829e9385bef6b007088a012bc3ceb0fa7867a8/packages/expect/src/asymmetricMatchers.ts#L59-L90This PR fixes that by adding in the missing
instanceof
checks.Test plan
There is a new unit test in the asymetric matcher test file which checks both the currently working cases and the currently broken ones.