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

Conversation

pedrottimark
Copy link
Contributor

Summary

Fixes #7443

Breaking change for upcoming major upgrade to Jest 24

cc @austinalameda @mweststrate

Goals:

  • Make snapshot tests consistent with toEqual matcher.
  • Omit implementation details from formatted object instances (for example, jsdom element or MobX observable).

Test plan

Added 2 test cases:

before after description
passed passed prints an object without non-enumerable properties which have string key
failed passed prints an object without non-enumerable properties which have symbol key

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

LGTM

CHANGELOG.md Outdated
@@ -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?

@rickhanlonii
Copy link
Member

@pedrottimark should we add a test for the snapshot matcher?

@codecov-io
Copy link

Codecov Report

Merging #7448 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #7448      +/-   ##
=========================================
+ Coverage    66.8%   66.8%   +<.01%     
=========================================
  Files         242     242              
  Lines        9374    9375       +1     
  Branches        6       5       -1     
=========================================
+ Hits         6262    6263       +1     
  Misses       3110    3110              
  Partials        2       2
Impacted Files Coverage Δ
packages/pretty-format/src/collections.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7d3870...8ea4290. Read the comment docs.

@pedrottimark
Copy link
Contributor Author

It looks like snapshot tests are not related to content. So integration test would be new e2e test.

For now in a local project:

@pedrottimark
Copy link
Contributor Author

Off topic of this PR, can y’all explain why existing code filters out symbols from array of keys?

const isSymbol = key =>
  // $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value
  typeof key === 'symbol' || toString.call(key) === '[object Symbol]';

  let keys = Object.keys(val).sort();

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

@rickhanlonii
Copy link
Member

Ah that's good enough for me!

@rickhanlonii rickhanlonii merged commit 36bb142 into jestjs:master Dec 3, 2018
@rickhanlonii
Copy link
Member

And no @pedrottimark I couldn't tell ya, did you blame it?

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

@pedrottimark pedrottimark deleted the non-enumerable-symbol branch December 3, 2018 17:17
thymikee added a commit to spion/jest that referenced this pull request Dec 18, 2018
* master: (24 commits)
  Add `jest.isolateModules` for scoped module initialization (jestjs#6701)
  Migrate to Babel 7 (jestjs#7016)
  docs: changed "Great Scott!" link (jestjs#7524)
  Use reduce instead of filter+map in dependency_resolver (jestjs#7522)
  Update Configuration.md (jestjs#7455)
  Support dashed args (jestjs#7497)
  Allow % based configuration of max workers (jestjs#7494)
  chore: Standardize filenames: jest-runner pkg (jestjs#7464)
  allow `bail` setting to control when to bail out of a failing test run (jestjs#7335)
  Add issue template labels (jestjs#7470)
  chore: standardize filenames in e2e/babel-plugin-jest-hoist (jestjs#7467)
  Add node worker-thread support to jest-worker (jestjs#7408)
  Add `testPathIgnorePatterns` to CLI documentation (jestjs#7440)
  pretty-format: Omit non-enumerable symbol properties (jestjs#7448)
  Add Jest Architecture overview to docs. (jestjs#7449)
  chore: run appveyor tests on node 10
  chore: fix failures e2e test for node 8 (jestjs#7446)
  chore: update docusaurus to v1.6.0 (jestjs#7445)
  Enhancement/expect-to-be-close-to-with-infinity (jestjs#7444)
  Update CHANGELOG formatting (jestjs#7429)
  ...
willsmythe pushed a commit to willsmythe/jest that referenced this pull request Dec 20, 2018
* pretty-format: Omit non-enumerable symbol properties

* Update CHANGELOG.md

* Correct CHANGELOG.md

* Move change line to other breaking under fixes
captain-yossarian pushed a commit to captain-yossarian/jest that referenced this pull request Jul 18, 2019
* pretty-format: Omit non-enumerable symbol properties

* Update CHANGELOG.md

* Correct CHANGELOG.md

* Move change line to other breaking under fixes
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Omit non-enumerable, symbolic members in snapshots
5 participants