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

fix: fix any() for symbols and bigints (#10179) #10223

Merged
merged 2 commits into from Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[expect]` Match symbols and bigints in `any()`; stop matching `null` ([#10223](https://github.com/facebook/jest/pull/10223))

### Chore & Maintenance

### Performance
Expand Down
4 changes: 4 additions & 0 deletions packages/expect/src/__tests__/asymmetricMatchers.test.ts
Expand Up @@ -29,7 +29,11 @@ test('Any.asymmetricMatch()', () => {
any(Number).asymmetricMatch(1),
any(Function).asymmetricMatch(() => {}),
any(Boolean).asymmetricMatch(true),
/* global BigInt */
any(BigInt).asymmetricMatch(1n),
any(Symbol).asymmetricMatch(Symbol()),
any(Object).asymmetricMatch({}),
!any(Object).asymmetricMatch(null),
any(Array).asymmetricMatch([]),
any(Thing).asymmetricMatch(new Thing()),
].forEach(test => {
Expand Down
11 changes: 10 additions & 1 deletion packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -46,13 +46,22 @@ class Any extends AsymmetricMatcher<any> {
}

if (this.sample == Object) {
return typeof other == 'object';
return typeof other == 'object' && other !== null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is kinda breaking, null is and Object in JS after all. Please revert

}

if (this.sample == Boolean) {
return typeof other == 'boolean';
}

/* global BigInt */
if (this.sample == BigInt) {
return typeof other == 'bigint';
}

if (this.sample == Symbol) {
return typeof other == 'symbol';
}

return other instanceof this.sample;
}

Expand Down