-
-
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
null nodes are passed to findWhere()/filterWhere() if tree contains stateless components #166
Comments
is this behavior actually specific to SFCs or is it just an awkwardness of how our node traversal logic works? |
I'm pretty sure it's specific to SFCs; according to the React docs,
I assume the reason you can't use refs on SFCs is that React doesn't even create ReactComponent instances for them. If that is the case it would certainly explain where the null nodes are coming from. |
In any case, I think |
This seems legitimate to me. I can't imagine a use case where i want to operate on |
Actually, I'm pretty sure "stateless functions don't have a backing instance" specifically means no |
It seems class Foo extends React.Component {
render() {
return (
<div>{this.props.children}</div>
);
}
}
it('should render without children', () => {
const wrapper = shallow(<Foo />);
const result = wrapper.findWhere(n => {
// necessary to check n.get(0) to avoid a thrown error from n.type()
return (n.get(0) !== null && n.type() === 'div')
});
} |
If the render tree contains stateless components (a.k.a. pure function components), wrappers with
null
node
s are passed tofindWhere()
and (I'm assuming)filterWhere()
.I can't imagine anything useful we could do with a null node passed to
findWhere
, plus this was unexpected to me, so I think it would be more helpful to avoid passing null nodes tofindWhere
.As an aside, this is not the first awkwardness since stateless components were introduced that makes me want to avoid using them...
The text was updated successfully, but these errors were encountered: