Skip to content

Commit

Permalink
Suggestion of fix for jestjs#7937
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Feb 20, 2019
1 parent be2703c commit d9dfdb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ describe('.toStrictEqual()', () => {
}).not.toStrictEqual({b: 2});
});

it('does not ignore keys with undefined values inside an array', () => {
expect([{a: undefined}]).not.toStrictEqual([{}]);
});

it('passes when comparing same type', () => {
expect({
test: new TestClassA(1, 2),
Expand Down
5 changes: 4 additions & 1 deletion packages/expect/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ export const sparseArrayEquality = (a: unknown, b: unknown) => {
// A sparse array [, , 1] will have keys ["2"] whereas [undefined, undefined, 1] will have keys ["0", "1", "2"]
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
return equals(a, b) && equals(aKeys, bKeys);
return (
equals(a, b, [iterableEquality, typeEquality], true) &&
equals(aKeys, bKeys)
);
};

export const partition = <T>(
Expand Down

0 comments on commit d9dfdb3

Please sign in to comment.