From 55e0d7e76c2d0538a2dcf7321645d3abf82bff82 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 2 Dec 2018 16:04:39 -0500 Subject: [PATCH 1/4] pretty-format: Omit non-enumerable symbol properties --- .../src/__tests__/prettyFormat.test.js | 24 +++++++++++++++++++ packages/pretty-format/src/collections.js | 5 +++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/pretty-format/src/__tests__/prettyFormat.test.js b/packages/pretty-format/src/__tests__/prettyFormat.test.js index 9d440352dbe5..12dafcdf35ac 100644 --- a/packages/pretty-format/src/__tests__/prettyFormat.test.js +++ b/packages/pretty-format/src/__tests__/prettyFormat.test.js @@ -261,6 +261,30 @@ describe('prettyFormat()', () => { ); }); + it('prints an object without non-enumerable properties which have string key', () => { + const val: any = { + enumerable: true, + }; + const key = 'non-enumerable'; + Object.defineProperty(val, key, { + enumerable: false, + value: false, + }); + expect(prettyFormat(val)).toEqual('Object {\n "enumerable": true,\n}'); + }); + + it('prints an object without non-enumerable properties which have symbol key', () => { + const val: any = { + enumerable: true, + }; + const key = Symbol('non-enumerable'); + Object.defineProperty(val, key, { + enumerable: false, + value: false, + }); + expect(prettyFormat(val)).toEqual('Object {\n "enumerable": true,\n}'); + }); + it('prints an object with sorted properties', () => { /* eslint-disable sort-keys */ const val = {b: 1, a: 2}; diff --git a/packages/pretty-format/src/collections.js b/packages/pretty-format/src/collections.js index 7a0f22561a84..fe802b59594e 100644 --- a/packages/pretty-format/src/collections.js +++ b/packages/pretty-format/src/collections.js @@ -162,7 +162,10 @@ export function printObjectProperties( ): string { let result = ''; let keys = Object.keys(val).sort(); - const symbols = getSymbols(val); + const symbols = getSymbols(val).filter( + //$FlowFixMe because property enumerable is missing in undefined + symbol => Object.getOwnPropertyDescriptor(val, symbol).enumerable, + ); if (symbols.length) { keys = keys.filter(key => !isSymbol(key)).concat(symbols); From acd10d566edd597e162b177925d6bc901b5414ee Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 2 Dec 2018 16:16:23 -0500 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 622c61c3e303..a064de083b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ - `[jest-haste-map]` Remove legacy condition for duplicate module detection ([#7333](https://github.com/facebook/jest/pull/7333)) - `[jest-haste-map]` Fix `require` detection with trailing commas and ignore `import typeof` modules ([#7385](https://github.com/facebook/jest/pull/7385)) - `[jest-cli]` Fix to set prettierPath via config file ([#7412](https://github.com/facebook/jest/pull/7412)) +- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7363](https://github.com/facebook/jest/pull/7448)) ### Chore & Maintenance From f51d2e920329013b613fa2d51f26a9ce9c2e2dd1 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 2 Dec 2018 16:17:31 -0500 Subject: [PATCH 3/4] Correct CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a064de083b7c..16d02f31ad6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,7 +77,7 @@ - `[jest-haste-map]` Remove legacy condition for duplicate module detection ([#7333](https://github.com/facebook/jest/pull/7333)) - `[jest-haste-map]` Fix `require` detection with trailing commas and ignore `import typeof` modules ([#7385](https://github.com/facebook/jest/pull/7385)) - `[jest-cli]` Fix to set prettierPath via config file ([#7412](https://github.com/facebook/jest/pull/7412)) -- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7363](https://github.com/facebook/jest/pull/7448)) +- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448)) ### Chore & Maintenance From 8ea4290a9c2cb2e6b3eac4a60a562993284890a5 Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sun, 2 Dec 2018 16:23:22 -0500 Subject: [PATCH 4/4] Move change line to other breaking under fixes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d02f31ad6d..4093c63ceafb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - `[jest-cli]` [**BREAKING**] Do not use `text-summary` coverage reporter by default if other reporters are configured ([#7058](https://github.com/facebook/jest/pull/7058)) - `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381)) - `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329)) +- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448)) - `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306)) - `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249)) - `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222)) @@ -77,7 +78,6 @@ - `[jest-haste-map]` Remove legacy condition for duplicate module detection ([#7333](https://github.com/facebook/jest/pull/7333)) - `[jest-haste-map]` Fix `require` detection with trailing commas and ignore `import typeof` modules ([#7385](https://github.com/facebook/jest/pull/7385)) - `[jest-cli]` Fix to set prettierPath via config file ([#7412](https://github.com/facebook/jest/pull/7412)) -- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448)) ### Chore & Maintenance