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 all commits
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()` ([#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
9 changes: 9 additions & 0 deletions packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -53,6 +53,15 @@ class Any extends AsymmetricMatcher<any> {
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