Skip to content

Commit

Permalink
pretty-format: Omit non-enumerable symbol properties (#7448)
Browse files Browse the repository at this point in the history
* pretty-format: Omit non-enumerable symbol properties

* Update CHANGELOG.md

* Correct CHANGELOG.md

* Move change line to other breaking under fixes
  • Loading branch information
pedrottimark authored and rickhanlonii committed Dec 3, 2018
1 parent 90132f5 commit 36bb142
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 24 additions & 0 deletions packages/pretty-format/src/__tests__/prettyFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 4 additions & 1 deletion packages/pretty-format/src/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 36bb142

Please sign in to comment.