Skip to content

Commit

Permalink
Suggestion of fix for #7937
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Feb 19, 2019
1 parent 8a2ea1e commit 4afb8dd
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.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ export const sparseArrayEquality = (a: any, b: any) => {
// 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 4afb8dd

Please sign in to comment.