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

jest-snapshot: Omit irrelevant received properties when property matchers fail #9198

Merged
merged 5 commits into from
Nov 17, 2019

Conversation

pedrottimark
Copy link
Contributor

Summary

Call getObjectSubset to be consistent with toMatchObject

  • a subset helps if a property is missing or obsolete however, there are bogus changes for the properties that match
  • although a subset hides the problem if there is a change to a key of a property, a minified serialization or even complete line diff of Expected properties versus Received value can also hide the problem in a mess of irrelevant details

Because the long-term solution is data-driven diff, please forgive a temporary hack to import getObjectSubset which is a private helper function of the expect package

Simen, when I wrote 'expect/src/utils' the package tests ran okay, but the example test outside Jest threw an error, so is this correct instead:

import {getObjectSubset} from 'expect/build/utils';

Test plan

In printSnapshot.test.ts

  • updated 3 snapshots
  • added 1 snapshot

Example picture baseline at left and improved at right

omit missing properties

@codecov-io
Copy link

codecov-io commented Nov 17, 2019

Codecov Report

Merging #9198 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9198   +/-   ##
=======================================
  Coverage   64.83%   64.83%           
=======================================
  Files         279      279           
  Lines       11742    11742           
  Branches     2887     2886    -1     
=======================================
  Hits         7613     7613           
  Misses       3511     3511           
  Partials      618      618
Impacted Files Coverage Δ
packages/jest-snapshot/src/printSnapshot.ts 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 03b97d6...3eb4fd7. Read the comment docs.

@@ -6,6 +6,7 @@
*/

import chalk = require('chalk');
import {getObjectSubset} from 'expect/build/utils';
Copy link
Member

Choose a reason for hiding this comment

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

this is correct, yeah

CHANGELOG.md Outdated Show resolved Hide resolved
@pedrottimark pedrottimark changed the title jest-snapshot: Omit irrelevant received properties jest-snapshot: Omit irrelevant received properties when property matchers fail Nov 17, 2019
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Wonderful, thank you!

@pedrottimark pedrottimark merged commit 8d0b5e2 into jestjs:master Nov 17, 2019
@pedrottimark pedrottimark deleted the snapshot-properties branch November 17, 2019 21:28
ayush000 added a commit to ayush000/jest that referenced this pull request Nov 21, 2019
* master:
  chore: upgrade to fsevents 2 (jestjs#9215)
  docs: remove expect.assertions(1) in rejects example of Tutoria… (jestjs#9149)
  chore: bump to istanbul alphas (jestjs#9192)
  Fix typo in JestPlatform.md (jestjs#9212)
  jest-snapshot: Ignore indentation for most serialized objects (jestjs#9203)
  fix(jest-types): tighten Config types and set more defaults (jestjs#9200)
  jest-snapshot: Improve colors when snapshots are updatable (jestjs#9132)
  jest-snapshot: Omit irrelevant received properties when property matchers fail (jestjs#9198)
  chore: make changedFiles option optional in `shouldInstrument` (jestjs#9197)
  fix(pretty-format): correctly detect memo (jestjs#9196)
  chore: regenerate lockfiles in e2e tests (jestjs#9193)
  chore: bump handlebars
@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 11, 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.

4 participants