Skip to content

Commit

Permalink
pretty-format: Omit unnecessary symbol filter for object keys (jestjs…
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrottimark authored and captain-yossarian committed Jul 18, 2019
1 parent d9cd9cf commit 4bab570
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 14 additions & 13 deletions packages/pretty-format/src/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4bab570

Please sign in to comment.