-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add an isEmptyRender()
method to both ShallowWrapper
and ReactWrapper
#339
Conversation
* | ||
* @returns {boolean} | ||
*/ | ||
isNull() { |
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.
I feel like this name too specifically implies that the component did return null
in its render
method, even though return undefined
(either explicitly or implicitly) should also be fine.
Seems like a lot changed internally during the React 15 upgrade. I've not been able to find an implementation that works across all versions. Using |
I think we need to duplicate all of these tests for The other question for me is the name. That said, I'm not really sure what the right name is. Maybe it should be |
Perhaps something like |
Ok, I changed it to |
isNull()
method to both ShallowWrapper
and ReactWrapper
isEmptyRender()
method to both ShallowWrapper
and ReactWrapper
* 'master' of github.com:airbnb/enzyme: Update docs to externalize react/addons for newer versions of React (#338)
Hey @milesj , you're right. My bad - I guess undefined is not valid here. We also want to ensure that this returns false in the proper cases though.
At the moment, I think at that point this will be ready to merge. Not super psyched about the name, but can't think of anything better at the moment.... so at least it's explicit. |
I was a bit surprised about the undefined thing as well. I could of sworn it allowed it at some point. I'll look into adding some truthy tests. |
Don't forget about |
@milesj any updates on this? 😄 |
Oops, thanks for reminding me. Been pretty swamped at work. Will try to get it this week. |
No worries, don't feel pressured/rushed! Thanks for the contribution, looking forward to seeing how this turns out 👍 |
Added a ton of return value checks. |
* 'master' of github.com:airbnb/enzyme: (30 commits) Update Jest docs. (#399) DOC: Clarify that .simulate() calls prop (#354) Beef up tests for SFCs and optimize npm test scripts Use public API for batchedUpdates ShallowRenderer supports batched updates grammar.. so trivial, sorry Id selector not working when combined with a tag selector (#314) Fix mount::simulate() signature (#381) Fix documentation code example mistake [lgtm] Fix capitalization of maintainer name, drop approvals to 1 v2.3.0 Add lgtm.co config and MAINTAINERS file. added error checking for state, setState, context, instance methods on ShallowWrapper (#373) equals should skip null and undefined nodes fix #151 (#192) Fix incorrect docs for type add docs related methods for .at() and .get() (#372) [Tests] remove io.js exclusions Add `name` method (#335) Test on node v6 Add loose equals and loose contains functions on ShallowWrapper (#362) ...
making it easier in tests to detect when a component renders nothing; either a null or undefined value. Fixed inconsistencies between React 0.14 and 15. Renamed isNull() to isEmptyRender(). Added tests for false checks. Added itWithData() and a better way to test possible falsey values for React render(). Added tests for components and element return types. Wrapped empty render data in a function. Simplify the empty render data checks.
@lelandrichardson I added tests that check null/false, as well as React components/elements. I originally had it testing every possible falsey value, but then it just barfed all over the output, as seen by the screenshot. I don't really see the benefit of testing all the falsey values as React doesn't allow anything besides null/false. |
@milesj I think we should only be testing valid "empty" return values 👍 |
What about |
I tested a ton of values, all of which are: null, false, undefined, NaN, array, empty array, object, empty object, zero, string, empty string, React element/component, DOM element, etc. All of them threw those warnings excluding null/false/React. |
LGTM |
@lelandrichardson Anything else you'd like done on this? Besides hitting the "Update Branch" button :P |
@milesj can you squash this to get read of all those merge commits? I think we can merge this after that 👍 |
Wouldn't Github's new merge squash feature suffice here? I've tried rebasing the history a bit, but it's turned out troublesome since the commits happened at different points in history. I'll mess around some more. |
Does Github do that now? I didn't realize, thats neat. I'll merge. Thanks again @milesj! |
(merge-squash is fine when the PR author has issues with rebasing, but in general we do strongly prefer rebased and non-squash-merged commits. github's squash-merge breaks the history between the PR and master) |
Yeah, GitHub's automatic "Update Branch" is useful, but annoying history wise. Will probably do it manually going forward. |
Why
Added an
isNull()
method to bothShallowWrapper
andReactWrapper
,making it easier in tests to detect when a component renders nothing;
either a null or undefined value.
I chose the name
isNull()
sinceisEmpty()
was used for other situations.It's not as descriptive as it could be, so open to suggestion.
Tested
Unit tests!