Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added inherited string keys check on subsetEquality method #13824

Merged
merged 5 commits into from Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions packages/expect-utils/src/utils.ts
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down