From 08f00e94f7fd8a4fc0c1eb3e01fe8d05b43538be Mon Sep 17 00:00:00 2001 From: ninevra Date: Thu, 2 Jul 2020 04:12:32 -0700 Subject: [PATCH] fix: any() for symbols and bigints (#10179) (#10223) * fix: fix any() for symbols, bigints, null (#10179) * revert change to null handling in any(Object) --- CHANGELOG.md | 2 ++ packages/expect/src/__tests__/asymmetricMatchers.test.ts | 4 ++++ packages/expect/src/asymmetricMatchers.ts | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cecfbc8229..1ed6626fd036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[expect]` Match symbols and bigints in `any()` ([#10223](https://github.com/facebook/jest/pull/10223)) + ### Chore & Maintenance ### Performance diff --git a/packages/expect/src/__tests__/asymmetricMatchers.test.ts b/packages/expect/src/__tests__/asymmetricMatchers.test.ts index b45e4c23d0b4..2474382c9ef8 100644 --- a/packages/expect/src/__tests__/asymmetricMatchers.test.ts +++ b/packages/expect/src/__tests__/asymmetricMatchers.test.ts @@ -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 => { diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index fa7293e0eaaa..7f9801602fcd 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -53,6 +53,15 @@ class Any extends AsymmetricMatcher { 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; }