Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Symbol based properties in arrays causes toEqual to throw #6391

Merged
merged 6 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fixes

- `[expect]` Using symbolic property names in arrays no longer causes the `toEqual` matcher to fail ([#6391](https://github.com/facebook/jest/pull/6391))
- `[expect]` `toEqual` no longer tries to compare non-enumerable symbolic properties, to be consistent with non-symbolic properties. ([#6398](https://github.com/facebook/jest/pull/6398))

## 23.1.0
Expand Down
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 @@ -443,6 +443,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);
});

test('non-enumerable members should be skipped during equal', () => {
const actual = {
x: 3,
Expand Down
3 changes: 2 additions & 1 deletion packages/expect/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ function keys(obj, isArray, hasKey) {
}

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