From af5d5a140b0c6ba386a4f88fefc5160ff6dffe02 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Wed, 15 Feb 2023 11:00:22 +0100 Subject: [PATCH] fix: added inherited string keys check on `subsetEquality` method (#13824) --- CHANGELOG.md | 1 + packages/expect-utils/src/utils.ts | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b61f448a93a..cb82e49b0b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes +- `[@jest/expect-utils]` `subsetEquality` should consider also an object's inherited string keys ([#13824](https://github.com/facebook/jest/pull/13824)) - `[jest-mock]` Clear mock state when `jest.restoreAllMocks()` is called ([#13867](https://github.com/facebook/jest/pull/13867)) - `[jest-mock]` Prevent `mockImplementationOnce` and `mockReturnValueOnce` bleeding into `withImplementation` ([#13888](https://github.com/facebook/jest/pull/13888)) - `[jest-mock]` Do not restore mocks when `jest.resetAllMocks()` is called ([#13866](https://github.com/facebook/jest/pull/13866)) diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 1a675c2c2349..89f0461b37f0 100644 --- a/packages/expect-utils/src/utils.ts +++ b/packages/expect-utils/src/utils.ts @@ -47,8 +47,6 @@ const hasPropertyInObject = (object: object, key: string | symbol): boolean => { // the prototype chain for string keys but not for symbols. (Otherwise, it // could find values such as a Set or Map's Symbol.toStringTag, with unexpected // results.) -// -// Compare with subsetEquality's use of Reflect.ownKeys. const getObjectKeys = (object: object) => [ ...Object.keys(object), ...Object.getOwnPropertySymbols(object), @@ -343,7 +341,7 @@ export const subsetEquality = ( return undefined; } - return Reflect.ownKeys(subset).every(key => { + return getObjectKeys(subset).every(key => { if (isObjectWithKeys(subset[key])) { if (seenReferences.has(subset[key])) { return equals(object[key], subset[key], filteredCustomTesters);