Skip to content

Commit af5d5a1

Browse files
authored
fix: added inherited string keys check on subsetEquality method (#13824)
1 parent 76ec2a4 commit af5d5a1

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Fixes
1010

11+
- `[@jest/expect-utils]` `subsetEquality` should consider also an object's inherited string keys ([#13824](https://github.com/facebook/jest/pull/13824))
1112
- `[jest-mock]` Clear mock state when `jest.restoreAllMocks()` is called ([#13867](https://github.com/facebook/jest/pull/13867))
1213
- `[jest-mock]` Prevent `mockImplementationOnce` and `mockReturnValueOnce` bleeding into `withImplementation` ([#13888](https://github.com/facebook/jest/pull/13888))
1314
- `[jest-mock]` Do not restore mocks when `jest.resetAllMocks()` is called ([#13866](https://github.com/facebook/jest/pull/13866))

packages/expect-utils/src/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const hasPropertyInObject = (object: object, key: string | symbol): boolean => {
4747
// the prototype chain for string keys but not for symbols. (Otherwise, it
4848
// could find values such as a Set or Map's Symbol.toStringTag, with unexpected
4949
// results.)
50-
//
51-
// Compare with subsetEquality's use of Reflect.ownKeys.
5250
const getObjectKeys = (object: object) => [
5351
...Object.keys(object),
5452
...Object.getOwnPropertySymbols(object),
@@ -343,7 +341,7 @@ export const subsetEquality = (
343341
return undefined;
344342
}
345343

346-
return Reflect.ownKeys(subset).every(key => {
344+
return getObjectKeys(subset).every(key => {
347345
if (isObjectWithKeys(subset[key])) {
348346
if (seenReferences.has(subset[key])) {
349347
return equals(object[key], subset[key], filteredCustomTesters);

0 commit comments

Comments
 (0)