-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 the matcher has properties #9104
Conversation
Instead of ordinary test failure (first) throw matcher error (second) Compare the preceding pictures for evidence of potential future improvement to call Instead of incorrect success (first) BREAKING throw matcher error (second) Instead of minified objects (first) display comparison lines (second) But continue to display minified objects if In the preceding picture, comparison lines of |
Codecov Report
@@ Coverage Diff @@
## master #9104 +/- ##
==========================================
+ Coverage 64.73% 64.76% +0.03%
==========================================
Files 277 277
Lines 11707 11720 +13
Branches 2874 2877 +3
==========================================
+ Hits 7578 7591 +13
Misses 3512 3512
Partials 617 617
Continue to review full report at Codecov.
|
Oh damn, this is really good! |
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. |
Summary
Borrow some features from
toMatchObject
for reports when snapshot matchers fail:Throw
Matcher error: received value must be an object when the matcher has properties
instead ofIn an ordinary test failure because received object does not match properties, display comparison lines if
isLineDiffable
A similarity with
toMatchObject
that I did not include isgetObjectSubset
because:But we decided that it is better to call
getObjectSubset
after all in #9198Refactor for clearer distinction between snapshot and generic serialization:
addExtraLineBreaks
inState.ts
for symmetry withremoveExtraLineBreaks
serialize
not to calladdExtraLineBreaks
minify
to callpretty-format
withmin: true
and otherserialize
optionsprintExpected
andprintReceived
to callminify
with colorsstringify
fromjest-matcher-utils
only forsnapshotState
errorTest plan
In
printSnapshot.test.ts
!isLineDiffable
isLineDiffable
printExpected
uses snapshot serializer optionsprintDiffOrStringified
withprintSnapshotAndReceived
In
utils.test.ts
edit 1toBe
becauseserialize
does not calladdExtraLineBreaks
In e2e
toMatchSnapshot.test.ts
edit 2toMatch
for comparison lines ifisLineDiffable
See also pictures in the following comment