Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty-format: Omit non-enumerable symbol properties #7448

Merged
merged 4 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#7448](https://github.com/facebook/jest/pull/7448))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the top of this section with the other breaking changes?


### Chore & Maintenance

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should this be a part of getSymbols, since it's only used in one place

);

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