diff --git a/CHANGELOG.md b/CHANGELOG.md index f77aa582ee69..60541aec1eb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 08aa419cc767..9c331c36e07e 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -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, diff --git a/packages/expect/src/jasmine_utils.js b/packages/expect/src/jasmine_utils.js index de423960f58a..144374f0cdff 100644 --- a/packages/expect/src/jasmine_utils.js +++ b/packages/expect/src/jasmine_utils.js @@ -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]); } }