-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: Add mountToDeepJson and mountToShallowJson #56
Conversation
Codecov Report
@@ Coverage Diff @@
## master #56 +/- ##
==========================================
+ Coverage 96.2% 96.84% +0.63%
==========================================
Files 5 5
Lines 79 95 +16
Branches 34 36 +2
==========================================
+ Hits 76 92 +16
Misses 2 2
Partials 1 1
Continue to review full report at Codecov.
|
Hey! Thanks a lot for your contribution, I haven't had time to take care of this project recently! Sorry, I'll review this PR when I get time, thanks again! |
Hey @pedrottimark, sorry for not reviewing this in time, I'll review it right now! |
Is there any difference between |
Thank you for asking. It took me some time to find a use case for that function :) Here are contrasting snapshots for the exports[`CheckboxWithLabel renders with mountToJson 1`] = `
<CheckboxWithLabel
labelOff="Off"
labelOn="On"
>
<label>
<input
checked={false}
onChange={[Function]}
type="checkbox"
/>
Off
</label>
</CheckboxWithLabel>
`;
exports[`CheckboxWithLabel renders with mountToDeepJson 1`] = `
<label>
<input
checked={false}
onChange={[Function]}
type="checkbox"
/>
Off
</label>
`;
exports[`CheckboxWithLabel renders with mountToShallowJson 1`] = `
<CheckboxWithLabel
labelOff="Off"
labelOn="On"
/>
`; Therefore
In an example at https://github.com/pedrottimark/whimper#create notice the export const tbodyShallow = ($table) => mountToShallowJson($table.find('tbody')); expect(tbodyShallow($it)).toMatchObject(relevantTestObject(
<tbody>
<TableRow record={recordDefault(fields)} />
<TableRow record={recordB} />
</tbody>
)); I am happy to answer your questions, because whenever I see something through the eyes of someone else, I must think more clearly about it. |
Forgot to say, it seems like intuitive expectation for
I forgot about the current return value until you asked, because in my example I used Redux Tests for simpler components could use a better return value for the top-level wrapper. |
Hi @pedrottimark! I am so sorry I didn't review this PR in time, I understand better what this is about now and I'm happy to merge it, thanks a lot for you contribution! |
Bonjour! The proof-of-concept for this pull request is a sample project about React testing: https://github.com/pedrottimark/whimper
To understand how valuable a part that
enzyme-to-json
has in it, start reading here: https://github.com/pedrottimark/whimper#interlude-about-snapshot-testingSummary, given an enzyme
mount
wrapper, especially from selector traversal:mountToDeepJson
returns a test object rendered to maximum depth (it contains only DOM nodes, no React components)mountToShallowJson
returns a test object rendered to minimum depth (it might contain DOM nodes, but any children which are React components are leaves of the tree)Here are some relevant issues:
relevantTestObject
function, it becomes a possible solution to Output mapping functionality #48 and Default props visible in shallow snapshot #55The changes to
shallow.js
and some inutils.js
were from prettier in pre-commit hook, I think.