Skip to content

Commit

Permalink
fix: fix any() for symbols, bigints, null (#10179)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninevra committed Jul 2, 2020
1 parent 22b8e85 commit cd23c45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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;
}

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

0 comments on commit cd23c45

Please sign in to comment.