From ef12e9683443985d6464f6611565a16543dbe065 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 5 Oct 2022 14:46:43 +0200 Subject: [PATCH] chore: when checking for asymmetricMatch, check for object --- packages/vitest/src/integrations/chai/jest-expect.ts | 2 +- packages/vitest/src/integrations/chai/jest-utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/integrations/chai/jest-expect.ts b/packages/vitest/src/integrations/chai/jest-expect.ts index 260c4928a69f..77a5fe0d1caf 100644 --- a/packages/vitest/src/integrations/chai/jest-expect.ts +++ b/packages/vitest/src/integrations/chai/jest-expect.ts @@ -548,7 +548,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { ) } - if ('asymmetricMatch' in expected && typeof (expected as any).asymmetricMatch === 'function') { + if (typeof expected === 'object' && 'asymmetricMatch' in expected && typeof (expected as any).asymmetricMatch === 'function') { const matcher = expected as any as AsymmetricMatcher return this.assert( thrown && matcher.asymmetricMatch(thrown), diff --git a/packages/vitest/src/integrations/chai/jest-utils.ts b/packages/vitest/src/integrations/chai/jest-utils.ts index 66d75641d76c..ffc75a7c2635 100644 --- a/packages/vitest/src/integrations/chai/jest-utils.ts +++ b/packages/vitest/src/integrations/chai/jest-utils.ts @@ -38,7 +38,7 @@ export function equals( const functionToString = Function.prototype.toString export function isAsymmetric(obj: any) { - return !!obj && 'asymmetricMatch' in obj && isA('Function', obj.asymmetricMatch) + return !!obj && typeof obj === 'object' && 'asymmetricMatch' in obj && isA('Function', obj.asymmetricMatch) } export function hasAsymmetric(obj: any, seen = new Set()): boolean {