-
-
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
Prevent falsy nodes from being counted as children #251
Conversation
const result = []; | ||
React.Children.forEach(maybeArray, child => result.push(child)); | ||
React.Children.forEach(filtered, child => result.push(child)); |
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.
a simpler solution here might be to just check and see if child
is false
, null
, or undefined
before pushing it into the result? The recursive nature of children will be taken care of in React.Children.forEach
in this case.
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.
Exactly.
Can I rewrite & send new PR?(I'm new to github...)
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.
@nishitaniyuki yep! Update your code and then push the changes to github. this PR should update automatically.
When you update your code, it's best for a change like this if you can make all of your changes into a single atomic commit. Let me know if you need any extra help with this.
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.
FYI, you can change the code and then use git commit --amend
to combine the changes into the latest commit so that it stays as a single commit.
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've combined the changes, thank you!
Please check it.
Thanks for working on this. I believe we omit these nodes from being passed into methods such as |
We omit |
@ljharb i'm not too worried about We explicitly don't traverse https://github.com/airbnb/enzyme/blob/master/src/ShallowTraversal.js#L32 |
I agree.
I expect this also should skip |
@nishitaniyuki great, thanks! |
Prevent falsy nodes from being counted as children
Like #151
I have a problem like below.
I expect
null
,undefined
andfalse
should not be counted as a child node.What do you think??