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

Change fail messages for toBeGreaterThan, toBeLessThan matchers #7134

Closed
wants to merge 4 commits into from
Closed

Change fail messages for toBeGreaterThan, toBeLessThan matchers #7134

wants to merge 4 commits into from

Conversation

jeffreypriebe
Copy link

Also changed toBeGreaterThanOrEqual, toBeLessThanOrEqual
Better reflects the fail condition

Closes #7105

Summary

When testing with toBeGreaterThan matcher, getting 'Expected: ${expected}' text doesn't jibe with mental expectation.

Test plan

Test snapshots updated.
Note: current master has failing tests, this PR only touches the relevant snapshots.

Also changed toBeGreaterThanOrEqual, toBeLessThanOrEqual
Better reflects the fail condition

Closes #7105
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.

Great improvement!

Looks like we need to handle the .not case now (see inline comments)

Let me know if I can help finish this out!

packages/expect/src/matchers.js Outdated Show resolved Hide resolved
@codecov-io
Copy link

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7134   +/-   ##
=======================================
  Coverage   66.43%   66.43%           
=======================================
  Files         253      253           
  Lines       10658    10658           
  Branches        4        3    -1     
=======================================
  Hits         7081     7081           
  Misses       3576     3576           
  Partials        1        1
Impacted Files Coverage Δ
packages/expect/src/matchers.js 97.45% <ø> (ø) ⬆️

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 24880d9...7575131. Read the comment docs.

@jeffreypriebe
Copy link
Author

Updated, thanks for the tips and direction @rickhanlonii @natealcedo.

@@ -587,462 +587,462 @@ Received: <red>undefined</>"
exports[`.toBeGreaterThan(), .toBeLessThan(), .toBeGreaterThanOrEqual(), .toBeLessThanOrEqual() equal numbers: [-Infinity, -Infinity] 1`] = `
"<dim>expect(</><red>received</><dim>).</>not<dim>.toBeGreaterThanOrEqual(</><green>expected</><dim>)</>

Expected: <green>-Infinity</>
Expected value not to be greater than or equal: <green>-Infinity</>
Received: <red>-Infinity</>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, now we don't align those 2 values so it's actually harder to compare. How about

Expected: 0 not to be greater than or equal to
Received: 0

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.

I don't agree this makes the assertion error any clearer. Why should we repeat the name of the matcher when listing out the values given to Jest? With this change we say "to be greater than" et.al. twice, which (IMO):

  • feels redundant (we already have expect(received).toBeGreaterThan(expected) in the error)
  • distracts from the assertion error (it doesn't align, I have to read more text to figure out what went wrong)
  • is very inconsistent with how other matchers are formatted in Jest (I can't think of a single case where it's not Expected: *value*\nReceived: *value* when comparing values)

@jeffreypriebe jeffreypriebe deleted the feature/improve-toBeGreaterThan-fail-message branch October 14, 2018 18:21
@rickhanlonii
Copy link
Member

@SimenB what about toEqual which says "Expected value to equal":

@SimenB
Copy link
Member

SimenB commented Oct 15, 2018

Hah, would you look at that! I think that's redundant as well 😅 However, that means this PR wasn't as inconsistent with the other matchers as I thought.

Maybe we can land this together with an overall look at more matcher, like @pedrottimark is doing in #7152? If all matchers followed the same general way of reporting assertion errors, I'd be happy to remove my objection to this PR

@pedrottimark
Copy link
Contributor

Yes, reports for the following matchers will get more concise labels in coming weeks:

  • toEqual
  • toStrictEqual
  • toHaveProperty
  • toMatch
  • toMatchObject

@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.

toBeGreaterThan message correction for failing case
8 participants