Skip to content

Commit b028e50

Browse files
authored
fix: not addressing to Sets and Maps as object without keys (#14873)
1 parent 1bf56dd commit b028e50

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
- `[@jest/expect-utils]` Fix comparison of `URL` ([#14672](https://github.com/jestjs/jest/pull/14672))
5454
- `[@jest/expect-utils]` Check `Symbol` properties in equality ([#14688](https://github.com/jestjs/jest/pull/14688))
5555
- `[@jest/expect-utils]` Catch circular references within arrays when matching objects ([#14894](https://github.com/jestjs/jest/pull/14894))
56+
- `[@jest/expect-utils]` Fix not addressing to Sets and Maps as objects without keys ([#14873](https://github.com/jestjs/jest/pull/14873))
5657
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
5758
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
5859
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))

packages/expect-utils/src/__tests__/utils.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,37 @@ describe('subsetEquality()', () => {
401401
});
402402
});
403403
});
404+
405+
describe('subset is not object with keys', () => {
406+
test('returns true if subset has keys', () => {
407+
expect(subsetEquality({foo: 'bar'}, {foo: 'bar'})).toBe(true);
408+
});
409+
test('returns true if subset has Symbols', () => {
410+
const symbol = Symbol('foo');
411+
expect(subsetEquality({[symbol]: 'bar'}, {[symbol]: 'bar'})).toBe(true);
412+
});
413+
test('returns undefined if subset has no keys', () => {
414+
expect(subsetEquality('foo', 'bar')).toBeUndefined();
415+
});
416+
test('returns undefined if subset is null', () => {
417+
expect(subsetEquality({foo: 'bar'}, null)).toBeUndefined();
418+
});
419+
test('returns undefined if subset is Error', () => {
420+
expect(subsetEquality({foo: 'bar'}, new Error())).toBeUndefined();
421+
});
422+
test('returns undefined if subset is Array', () => {
423+
expect(subsetEquality({foo: 'bar'}, [])).toBeUndefined();
424+
});
425+
test('returns undefined if subset is Date', () => {
426+
expect(subsetEquality({foo: 'bar'}, new Date())).toBeUndefined();
427+
});
428+
test('returns undefined if subset is Set', () => {
429+
expect(subsetEquality({foo: 'bar'}, new Set())).toBeUndefined();
430+
});
431+
test('returns undefined if subset is Map', () => {
432+
expect(subsetEquality({foo: 'bar'}, new Map())).toBeUndefined();
433+
});
434+
});
404435
});
405436

406437
describe('iterableEquality', () => {

packages/expect-utils/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ const isObjectWithKeys = (a: any) =>
336336
isObject(a) &&
337337
!(a instanceof Error) &&
338338
!Array.isArray(a) &&
339-
!(a instanceof Date);
339+
!(a instanceof Date) &&
340+
!(a instanceof Set) &&
341+
!(a instanceof Map);
340342

341343
export const subsetEquality = (
342344
object: unknown,

0 commit comments

Comments
 (0)