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: Improve report when matcher fails, part 14 #8132

Merged
merged 13 commits into from
Mar 19, 2019

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Mar 15, 2019

Summary

4 snapshot matchers

Correct: matcher name in regular black

Complete:

  • modifiers .rejects, .resolves, or .not
  • expected arguments name hint, properties, or snapshot

Clear:

  • short labels and aligned property values
  • snapshot key name value as template literal same as in .snap file
  • optional snapshot name in green hint in bold font weight

Consistent: 'Received function did not throw' from toThrow matcher

Residue:

  • display matcher hint with more existing errors
  • BREAKING: throw errors for inconsistent expected arguments and received values
  • refactor redundant logic for values and their descriptions for matcher hint

Test plan

Updated e2e tests:

criteria file
2 snapshots failures.test.ts.snap
1 snapshot watchModeUpdateSnapshot.test.ts.snap
2 match strings toMatchInlineSnapshot.test.ts
8 match strings toMatchSnapshot.test.ts
1 match string toThrowErrorMatchingInlineSnapshot.test.ts
2 match strings toThrowErrorMatchingSnapshot.test.ts
1 error match string snapshot.test.js

See also pictures in following comment.

@pedrottimark
Copy link
Contributor Author

pedrottimark commented Mar 15, 2019

Example pictures baseline followed by improved

.toMatchSnapshot correct hint has both args, short label with optional name in green bold font weight, align values on same line as labels:

toMatchSnapshot baseline

Updated according to #8132 (comment)

toMatchSnapshot properties improved 4

.resolves.toMatchSnapshot correct hint and short label with key in black:

toMatchSnapshot resolves baseline

Updated according to #8132 (comment)

toMatchSnapshot resolves improved 2

.not.toMatchInlineSnapshot displays matcher hint:

toMatchInlineSnapshot not baseline

Updated according to #8132 (comment)

toMatchInlineSnapshot not improved 2

.toThrowErrorMatchingSnapshot same “did not throw” message as .toThrow matcher:

toThrowErrorMatchingSnapshot baseline

toThrowErrorMatchingSnapshot improved

.rejects.toThrowErrorMatchingInlineSnapshot correct and complete hint:

toThrowErrorMatchingInlineSnapshot baseline

Updated according to #8132 (comment)

toThrowErrorMatchingInlineSnapshot improved 2

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

I really like the direction it's going. Left a few inline comments to consider

packages/jest-snapshot/src/index.ts Outdated Show resolved Hide resolved
packages/jest-snapshot/src/index.ts Outdated Show resolved Hide resolved
docs/ExpectAPI.md Outdated Show resolved Hide resolved
e2e/__tests__/__snapshots__/failures.test.ts.snap Outdated Show resolved Hide resolved
@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.

5 participants