Skip to content

Commit

Permalink
Fixed issue where jest fails to compare symbol properties in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jun 4, 2018
1 parent 241588a commit 2d85979
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,19 @@ describe('.toEqual()', () => {
);
}
});

test('symbol based keys in arrays are processed correctly', () => {
const mySymbol = Symbol("test");
const actual1 = [];
actual1[mySymbol] = 3;
const actual2 = [];
actual2[mySymbol] = 4;
const expected = [];
expected[mySymbol] = 3;

expect(actual1).toEqual(expected);
expect(actual2).not.toEqual(expected);
})
});

describe('.toBeInstanceOf()', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function keys(obj, isArray, hasKey) {
}

for (var x = 0; x < allKeys.length; x++) {
if (!allKeys[x].match(/^[0-9]+$/)) {
if (typeof allKeys[x] === 'symbol' || !allKeys[x].match(/^[0-9]+$/)) {
extraKeys.push(allKeys[x]);
}
}
Expand Down

0 comments on commit 2d85979

Please sign in to comment.