From 2d85979a3a8b1e7ac7c2dfc8d375ccb1b093a532 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jun 2018 13:52:59 +0200 Subject: [PATCH 1/5] Fixed issue where jest fails to compare symbol properties in arrays --- packages/expect/src/__tests__/matchers.test.js | 13 +++++++++++++ packages/expect/src/jasmine_utils.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 69e04a4e79b8..b979ed0c0fe8 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -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()', () => { diff --git a/packages/expect/src/jasmine_utils.js b/packages/expect/src/jasmine_utils.js index 6fc2f6d2e89f..e066a4715184 100644 --- a/packages/expect/src/jasmine_utils.js +++ b/packages/expect/src/jasmine_utils.js @@ -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]); } } From 6fd71aac1e7c84327ccdbe99023e202e127e6b0e Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jun 2018 14:04:43 +0200 Subject: [PATCH 2/5] Updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 522e3fbd349e..5f9a84d4eaf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ ## master +### Fixes + ## 23.1.0 +- `[expect]` Using symbolic property names in arrays no longer causes the `toEqual` matcher to fail ([#6391](https://github.com/facebook/jest/pull/6391)) + ### Features - `[jest-each]` Add pretty-format serialising to each titles ([#6357](https://github.com/facebook/jest/pull/6357)) From 5cdc2535924ba0f4c9442ea52d0e79ec56c8f9be Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jun 2018 14:10:41 +0200 Subject: [PATCH 3/5] fixup changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f9a84d4eaf2..c7625d335fb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ ### Fixes -## 23.1.0 - - `[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 - `[jest-each]` Add pretty-format serialising to each titles ([#6357](https://github.com/facebook/jest/pull/6357)) From cf7d2a11060900ebd574eba658cfc041f5eef87e Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jun 2018 14:47:50 +0200 Subject: [PATCH 4/5] Fixed linting errors --- packages/expect/src/__tests__/matchers.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index b979ed0c0fe8..cc473231dcf1 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -444,7 +444,7 @@ describe('.toEqual()', () => { }); test('symbol based keys in arrays are processed correctly', () => { - const mySymbol = Symbol("test"); + const mySymbol = Symbol('test'); const actual1 = []; actual1[mySymbol] = 3; const actual2 = []; @@ -454,7 +454,7 @@ describe('.toEqual()', () => { expect(actual1).toEqual(expected); expect(actual2).not.toEqual(expected); - }) + }); }); describe('.toBeInstanceOf()', () => { From 6538f68764d3a909b196e0cacea384ac40fa189f Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jun 2018 15:32:06 +0200 Subject: [PATCH 5/5] Supress incorrect flow error --- packages/expect/src/jasmine_utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/expect/src/jasmine_utils.js b/packages/expect/src/jasmine_utils.js index e066a4715184..158c07248019 100644 --- a/packages/expect/src/jasmine_utils.js +++ b/packages/expect/src/jasmine_utils.js @@ -222,6 +222,7 @@ function keys(obj, isArray, hasKey) { } for (var x = 0; x < allKeys.length; x++) { + //$FlowFixMe if (typeof allKeys[x] === 'symbol' || !allKeys[x].match(/^[0-9]+$/)) { extraKeys.push(allKeys[x]); }