Skip to content

Commit

Permalink
fix: any() for symbols and bigints (#10179) (#10223)
Browse files Browse the repository at this point in the history
* fix: fix any() for symbols, bigints, null (#10179)

* revert change to null handling in any(Object)
  • Loading branch information
ninevra committed Jul 2, 2020
1 parent 22b8e85 commit 08f00e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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

0 comments on commit 08f00e9

Please sign in to comment.