diff --git a/CHANGELOG.md b/CHANGELOG.md index eb01e7a54b6d..43160fd7f324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,7 @@ - `[jest-cli]` Fix to run in band tests if watch mode enable when runInBand arg used ([#7518](https://github.com/facebook/jest/pull/7518)) - `[jest-runtime]` Fix mistake as test files when run coverage issue. ([#7506](https://github.com/facebook/jest/pull/7506)) - `[jest-cli]` print info about passWithNoTests flag ([#7309](https://github.com/facebook/jest/pull/7309)) +- `[pretty-format]` Omit unnecessary symbol filter for object keys ([#7457](https://github.com/facebook/jest/pull/7457)) ### Chore & Maintenance diff --git a/packages/pretty-format/src/collections.js b/packages/pretty-format/src/collections.js index fe802b59594e..bfde775c28f1 100644 --- a/packages/pretty-format/src/collections.js +++ b/packages/pretty-format/src/collections.js @@ -9,11 +9,20 @@ import type {Config, Printer, Refs} from 'types/PrettyFormat'; -const getSymbols = Object.getOwnPropertySymbols || (obj => []); +const getKeysOfEnumerableProperties = (object: Object) => { + const keys = Object.keys(object).sort(); + + if (Object.getOwnPropertySymbols) { + Object.getOwnPropertySymbols(object).forEach(symbol => { + //$FlowFixMe because property enumerable is missing in undefined + if (Object.getOwnPropertyDescriptor(object, symbol).enumerable) { + keys.push(symbol); + } + }); + } -const isSymbol = key => - // $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value - typeof key === 'symbol' || toString.call(key) === '[object Symbol]'; + return keys; +}; // Return entries (for example, of a map) // with spacing, indentation, and comma @@ -161,15 +170,7 @@ export function printObjectProperties( printer: Printer, ): string { let result = ''; - let keys = Object.keys(val).sort(); - 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); - } + const keys = getKeysOfEnumerableProperties(val); if (keys.length) { result += config.spacingOuter;