From 0857e7ef711d803232d95e32db153202f0111b37 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Thu, 26 Jan 2023 12:36:03 +0100 Subject: [PATCH 1/3] fix: added inherited string keys check on subsetEquality method --- packages/expect-utils/src/utils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 0c1cc7b243fe..38d6b17c497e 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); From 87c641991f45c14f7cc023361914252960cbb648 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Thu, 26 Jan 2023 12:41:19 +0100 Subject: [PATCH 2/3] added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3b22b37435..c417e81d7781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[@jest/expect-utils]` `toMatchObject` diffs should include `Symbol` properties ([#13810](https://github.com/facebook/jest/pull/13810)) +- `[@jest/expect-utils]` `subsetEquality` should consider also an object's inherited string keys ([#13824](https://github.com/facebook/jest/pull/13824)) ### Chore & Maintenance From faaf8b50b7b67846673566e4de67eae929ee69b8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 15 Feb 2023 10:59:32 +0100 Subject: [PATCH 3/3] move changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f284cc1b0a..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)) @@ -46,7 +47,6 @@ ### Fixes - `[@jest/expect-utils]` `toMatchObject` diffs should include `Symbol` properties ([#13810](https://github.com/facebook/jest/pull/13810)) -- `[@jest/expect-utils]` `subsetEquality` should consider also an object's inherited string keys ([#13824](https://github.com/facebook/jest/pull/13824)) - `[jest-runtime]` Handle missing `replaceProperty` ([#13823](https://github.com/facebook/jest/pull/13823)) - `[@jest/types]` Add partial support for `done` callbacks in typings of `each` ([#13756](https://github.com/facebook/jest/pull/13756))