-
Notifications
You must be signed in to change notification settings - Fork 355
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
chore(testing): adds enzyme and updates existing tests #258
Conversation
66eaed6
to
f2656c2
Compare
Pull Request Test Coverage Report for Build 938
💛 - Coveralls |
3b43500
to
e4bf1ef
Compare
@@ -1,3 +1,5 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`AboutModal renders correctly when hidden 1`] = `null`; | |||
|
|||
exports[`AboutModal renders correctly when shown 1`] = `"<div role=\\"dialog\\"><div class=\\"modal-backdrop fade in\\"></div><div role=\\"dialog\\" tabindex=\\"-1\\" style=\\"display: block; padding-right: 0px;\\" class=\\"fade in modal\\"><div class=\\"modal-dialog\\"><div class=\\"modal-content about-modal-pf\\" role=\\"document\\"><div class=\\"modal-header\\"><button class=\\"close\\"><span aria-hidden=\\"true\\" class=\\"pficon pficon-close\\" title=\\"Close\\"></span><span class=\\"sr-only\\">Close</span></button></div><div class=\\"modal-body\\"><h1>Product Title</h1><div class=\\"product-versions-pf\\"><ul class=\\"list-unstyled\\"><li class=\\"\\"><strong>Label</strong> Version</li></ul></div><div class=\\"trademark-pf\\">Trademark and Copyright Information</div></div><div class=\\"modal-footer\\"><img src=\\"\\" alt=\\"Patternfly Logo\\"></div></div></div></div></div>"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any way to clean up this snapshot? the way component.html()
is snapping is not so pretty...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say "not so pretty" and "clean up" I understand your meaning to be, that the single line escaped html output is difficult to read at a glance. The formatting is shite, is that about right?
Or is your issue with the type of output? I would argue the content rendered by a component far more meaningful than alternatives what is rendered when prop show = true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se how we use enzyme-to-json
in foreman:
https://github.com/theforeman/foreman/blob/develop/webpack/assets/javascripts/react_app/components/common/Alert/AlertBody.test.js#L11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sharvit greaaaaaaaaat suggestion! while the wrapper type is different, mount
vs shallow
used in foreman... it looks like the .render()
output yields the same result... will go back and fixup a few other instances in this pr on monday
@AllenBW do you mind summarizing your thoughts thus far? I guess i am still seeing Enzyme as a supplement to jest snapshots (not a replacement)...from the Jest docs: https://facebook.github.io/jest/docs/en/snapshot-testing.html#does-snapshot-testing-substitute-unit-testing). So Enzyme helps a lot with the event based/interactive tests, but we can get a lot of coverage from the simple prop based/snapshot based tests. I don't see the need to duplicate test coverage "just because" of older conventions I guess is what I am after... The snapshots scale really well w/ regressions (as we can update them quickly and visually see what's changing). For example, if you were to change the default class of the Now the other thing I think we have to continue reminding folks of is - Jest/Enzyme snapshots run headlessly (no browser needed). So they give us the unit/integration level tests (but not e2e). But that is exactly the point... they run super fast and give us insights immediately as we develop and let us focus on fixing on our own bugs rather than the browsers 😸 . |
@AllenBW maybe you'd like to present on this topic at a future PF React Community meeting? |
@priley86 tl;dr Thoughts, greater flexibility, less code, more natural setup and use, works to make snapshots more meaningful. This is not a replacement for jest snapshots, if for anything, possibly
As yah can see, code is require, reading along is just a lil bit more natural. Also yah, if this is something that sticks, yeah wouldn't mind presenting pfr community meeting. Our coverage sucks. Why does our coverage suck? Because functions are not invoked during testing. Why are functions not being invoked during testing? Because stubbing live components yah can poke n prod can be tricky. Enzyme, this work, makes it less tricky by being able to either mount render or shallow instantiate components. With the apis each of those wrappers expose, devs are able to do a BUNCH of things, ones that I have done in this work, (still more to do, gimme a break i'm new at this one) include rendering components as html (rather than a giant jsx-ish json) assess the outcome of props rather than just their values... 🌮 💃 🥑 |
ps, still a wip. |
I really appreciate all this W.I.P. discussion candy... it makes me so hungry though haha ^^ 🍨 🍬 😋 and appreciate the research already @AllenBW 👍 |
b487707
to
9ced7eb
Compare
@AllenBW I think you can learn a lot about enzyme/jest/snapshots from theforeman/foreman#5240 Especially from: |
a4c71c6
to
2e7b768
Compare
indirectly related... but we still need to find a way to test the react-overlays / Modals as well...and just mentioning an upstream response on this yesterday (not sure that it helps yet): |
@priley86 did yah checkout the about modal snapshot? when a component is wrapped in a mount we're able to interact with it throughout the lifecycle |
ce15d86
to
7f07909
Compare
i'm just watching the test coverage go up up up before my 👁 👁 's ... this is incredible... |
7f07909
to
5bf4ee9
Compare
5bf4ee9
to
7d2e928
Compare
@jeff-phillips-18 @patternfly-build @sharvit @anyone_else? So steps forward for this pr, a few additional components have been added since this... (5 to be exact), can we get this in, circle back around and update those tests? (and then pull the depreciated dep) OR do it here, hopefully get this in before more new components are merged? |
@AllenBW please feel free to continue the Enzyme magic as you have time...this was a huge huge win for us already. |
Thats the plan!! 😋 🙇♀️ |
closes #257
Yah might be wondering, why doesn't this pr drastically increase test coverage! Scope. While many test files were touched, the changes are similar and new tests have not been written (ok well there are a few, but not many)
This also updates jest so we can use super fancy snapshotSerializers
This also adds a few needed coverage reporting deps semi related to: #jestjs/jest#5772
I'd really like to pull
"react-test-renderer": "^16.2.0"
from 📦 butttttt as new features are merged, they are using the old testing ⚙️, I just can't keep up 😩