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 all 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 @@ -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,
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