Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
- `[@jest/expect-utils]` [**BREAKING**] exclude non-enumerable in object matching ([#14670](https://github.com/jestjs/jest/pull/14670))
- `[@jest/expect-utils]` Fix comparison of `URL` ([#14672](https://github.com/jestjs/jest/pull/14672))
- `[@jest/expect-utils]` Check `Symbol` properties in equality ([#14688](https://github.com/jestjs/jest/pull/14688))
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
Expand Down
30 changes: 30 additions & 0 deletions packages/expect-utils/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,36 @@ describe('iterableEquality', () => {
const b = new TestRecord().set('dummy', 'data');
expect(iterableEquality(a, b)).toBe(true);
});

test('returns true when given a symbols keys within equal objects', () => {
const KEY = Symbol();

const a = {
[Symbol.iterator]: () => ({next: () => ({done: true})}),
[KEY]: [],
};
const b = {
[Symbol.iterator]: () => ({next: () => ({done: true})}),
[KEY]: [],
};

expect(iterableEquality(a, b)).toBe(true);
});

test('returns false when given a symbols keys within inequal objects', () => {
const KEY = Symbol();

const a = {
[Symbol.iterator]: () => ({next: () => ({done: true})}),
[KEY]: [1],
};
const b = {
[Symbol.iterator]: () => ({next: () => ({done: true})}),
[KEY]: [],
};

expect(iterableEquality(a, b)).toBe(false);
});
});

describe('typeEquality', () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ export const iterableEquality = (
!isImmutableOrderedSet(a) &&
!isImmutableRecord(a)
) {
const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
const aEntries = entries(a);
const bEntries = entries(b);
if (!equals(aEntries, bEntries)) {
return false;
}
Expand All @@ -320,6 +320,15 @@ export const iterableEquality = (
return true;
};

const entries = (obj: any) => {
if (!isObject(obj)) return [];

return Object.getOwnPropertySymbols(obj)
.filter(key => key !== Symbol.iterator)
.map(key => [key, obj[key]])
.concat(Object.entries(obj));
};

const isObject = (a: any) => a !== null && typeof a === 'object';

const isObjectWithKeys = (a: any) =>
Expand Down