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

Improve description line when assertion fails: part 1 #5437

Merged
merged 4 commits into from
Feb 7, 2018

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Feb 2, 2018

Summary

First in series of pull requests for clearer shorter report when assertion fails.

To warm up, let’s sweat some small stuff :) //cc @thymikee @rickhanlonii

Apply two principles from The Non-Designer’s Design Book by Robin Williams:

  1. Contrast: Format comma separating primary and secondary argument as dim instead of regular for toHaveProperty assertion.

compare_tohaveproperty

  1. Contrast: Format comma separating primary and secondary argument as dim instead of green for toBeCloseTo which concatenated names instead of providing secondary as option.

compare_tobecloseto

  1. Proximity: Format supplementary information as dim comment [EDIT on 2018-02-05: // Object.is equality to be parallel with // strict equality and // deep equality in next PR] at end of line instead labels in label Expected value to be (using Object.is) of values, which a future pull request will omit when there is a diff.

5437_3_tobe

Test plan

  1. Updated 24 snapshot tests in 1 test suite.
  2. Updated 12 snapshot tests in 1 test suite. Most of snapshots omit the option because arg is omitted (for a more accurate description) following example of formatting for toHaveProperty assertion.
  3. Updated 19 snapshot tests in 2 test suites.

@codecov-io
Copy link

codecov-io commented Feb 2, 2018

Codecov Report

Merging #5437 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5437      +/-   ##
==========================================
- Coverage   62.18%   62.17%   -0.01%     
==========================================
  Files         205      205              
  Lines        6928     6927       -1     
  Branches        3        4       +1     
==========================================
- Hits         4308     4307       -1     
  Misses       2619     2619              
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-matcher-utils/src/index.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 dea270b...27c4f66. Read the comment docs.

@@ -504,7 +504,7 @@ Received:
`;

exports[`.toBeCloseTo() throws: [1.23, 1.2249999] 1`] = `
"<dim>expect(</><red>received</><dim>).toBeCloseTo(</><green>expected, precision</><dim>)</>
"<dim>expect(</><red>received</><dim>).toBeCloseTo(</><green>expected</><dim>)</>
Copy link
Collaborator

Choose a reason for hiding this comment

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

One of toBeCloseTo snapshots should have a precision param set.

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, see 3 tests for accepts an optional precision argument like needles in the haystack just above this last set of 3 for throws however I will make a note to self that there do not seem to be any tests that assertion throws error if either arg is not number.

isDirectExpectCall?: boolean,
secondArgument?: ?string,
},
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 set this to have a default value of = {} to avoid further options && checks?

@thymikee
Copy link
Collaborator

thymikee commented Feb 2, 2018

I actually like it this way!

@cpojer
Copy link
Member

cpojer commented Feb 2, 2018

Good stuff indeed!

@rickhanlonii
Copy link
Member

Love it, great attention to detail here @pedrottimark!

@pedrottimark
Copy link
Contributor Author

By the way, part 2 will include one CHANGELOG item for both, if you will excuse me on this one ;)

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

6 participants