Skip to content

Commit

Permalink
Fix not addressing to Sets as object without keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekm97 committed Jan 29, 2024
1 parent 38bb798 commit 1557ff2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/expect-utils/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,34 @@ describe('subsetEquality()', () => {
});
});
});

describe('subset is not object with keys', () => {
test('returns true if subset has keys', () => {
expect(subsetEquality({foo: 'bar'}, {foo: 'bar'})).toBe(true);
});
test('returns true if subset has Symbols', () => {
const symbol = Symbol('foo');
expect(subsetEquality({[symbol]: 'bar'}, {[symbol]: 'bar'})).toBe(true);
});
test('returns undefined if subset has no keys', () => {
expect(subsetEquality('foo', 'bar')).toBeUndefined();
});
test('returns undefined if subset is null', () => {
expect(subsetEquality({foo: 'bar'}, null)).toBeUndefined();
});
test('returns undefined if subset is Error', () => {
expect(subsetEquality({foo: 'bar'}, new Error())).toBeUndefined();
});
test('returns undefined if subset is Array', () => {
expect(subsetEquality({foo: 'bar'}, [])).toBeUndefined();
});
test('returns undefined if subset is Date', () => {
expect(subsetEquality({foo: 'bar'}, new Date())).toBeUndefined();
});
test('returns undefined if subset is Set', () => {
expect(subsetEquality({foo: 'bar'}, new Set())).toBeUndefined();
});
});
});

describe('iterableEquality', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ const isObjectWithKeys = (a: any) =>
isObject(a) &&
!(a instanceof Error) &&
!Array.isArray(a) &&
!(a instanceof Date);
!(a instanceof Date) &&
!(a instanceof Set);

export const subsetEquality = (
object: unknown,
Expand Down

0 comments on commit 1557ff2

Please sign in to comment.