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

Call jest-diff and pretty-format more precisely in toHaveProperty matcher #4445

Merged
merged 2 commits into from
Sep 14, 2017

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Sep 7, 2017

Summary

EDITED:

  • Call diff if and only if valuePassed && hasEndProp
  • Call pretty-format for received property value, not for its parent object
  • Received is lastTraversedObject if and only if traversedPath non-empty and incomplete

Test plan

Updated 3 snapshots

? diff(value, result.value, {
expand: this.expand,
})
: '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put this in one line for readability?

? diff(value, result.value, {expand: this.expand})
: '';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good call.

(hasEndProp
? `Received:\n` +
` ${printReceived(result.value)}` +
(diffString ? `\n\nDifference:\n\n${diffString}` : '')
Copy link
Collaborator

Choose a reason for hiding this comment

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

\n\nDifference

is this double newline intended? Old code has only one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I see from snapshot that it actually looks better now 👍

Copy link
Contributor Author

@pedrottimark pedrottimark Sep 8, 2017

Choose a reason for hiding this comment

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

EDIT: Good eyes! Yes, the double newline is following pattern of toEqual matcher.

@pedrottimark pedrottimark changed the title Call diff more precisely in toHaveProperty matcher Call jest-diff and pretty-format more precisely in toHaveProperty matcher Sep 8, 2017
@pedrottimark
Copy link
Contributor Author

pedrottimark commented Sep 8, 2017

EDIT: It’s not yet clear to me if eager evaluation of diff caused perf problem for examples in #3847

@cpojer cpojer merged commit 8529bd1 into jestjs:master Sep 14, 2017
@pedrottimark pedrottimark deleted the to-have-property branch September 14, 2017 14:14
tabrindle pushed a commit to tabrindle/jest that referenced this pull request Oct 2, 2017
…cher (jestjs#4445)

* Call diff more precisely in toHaveProperty matcher

* Write diff call on one line for readability
@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 13, 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