Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## master

### Fixes

- `[expect]` Using symbolic property names in arrays no longer causes the `toEqual` matcher to fail ([#6391](https://github.com/facebook/jest/pull/6391))

## 23.1.0

### Features
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 @@ -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
3 changes: 2 additions & 1 deletion packages/expect/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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]+$/)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a FlowFixMe comment above this, flow is wrong.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed, used //$FlowFixMe. Hopefully that is correct, I am flow noob :)

extraKeys.push(allKeys[x]);
}
}
Expand Down