Skip to content

Commit 5332582

Browse files
pedrottimarkcaptain-yossarian
authored andcommitted
pretty-format: Omit non-enumerable symbol properties (jestjs#7448)
* pretty-format: Omit non-enumerable symbol properties * Update CHANGELOG.md * Correct CHANGELOG.md * Move change line to other breaking under fixes
1 parent e0a559f commit 5332582

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- `[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))
4040
- `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381))
4141
- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
42+
- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448))
4243
- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
4344
- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
4445
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))

packages/pretty-format/src/__tests__/prettyFormat.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,30 @@ describe('prettyFormat()', () => {
261261
);
262262
});
263263

264+
it('prints an object without non-enumerable properties which have string key', () => {
265+
const val: any = {
266+
enumerable: true,
267+
};
268+
const key = 'non-enumerable';
269+
Object.defineProperty(val, key, {
270+
enumerable: false,
271+
value: false,
272+
});
273+
expect(prettyFormat(val)).toEqual('Object {\n "enumerable": true,\n}');
274+
});
275+
276+
it('prints an object without non-enumerable properties which have symbol key', () => {
277+
const val: any = {
278+
enumerable: true,
279+
};
280+
const key = Symbol('non-enumerable');
281+
Object.defineProperty(val, key, {
282+
enumerable: false,
283+
value: false,
284+
});
285+
expect(prettyFormat(val)).toEqual('Object {\n "enumerable": true,\n}');
286+
});
287+
264288
it('prints an object with sorted properties', () => {
265289
/* eslint-disable sort-keys */
266290
const val = {b: 1, a: 2};

packages/pretty-format/src/collections.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ export function printObjectProperties(
162162
): string {
163163
let result = '';
164164
let keys = Object.keys(val).sort();
165-
const symbols = getSymbols(val);
165+
const symbols = getSymbols(val).filter(
166+
//$FlowFixMe because property enumerable is missing in undefined
167+
symbol => Object.getOwnPropertyDescriptor(val, symbol).enumerable,
168+
);
166169

167170
if (symbols.length) {
168171
keys = keys.filter(key => !isSymbol(key)).concat(symbols);

0 commit comments

Comments
 (0)