react-shallow-testutils
react-shallow-testutils copied to clipboard
findAllWithType is not functioning correctly
Firstly, are you accepting PRs on this project?
Second, consider the following code:
var Test = React.createClass({
render: function() {
return <div><TestTwo /></div>
}
});
var TestTwo = React.createClass({
render: function() {
return <div> 'hi'</div>
}
})
renderer = new ShallowRenderer.Renderer;
component = renderer.render(Test, {}, {});
ShallowRenderer.findAllWithType(component, 'TestTwo')
Should this return an array with one element representing the TestTwo component? It is currently returning an empty array. I'm trying to verify that I am using this correctly.
It looks as if .type passed to findAll is not returning the correct value.
Yeah, of course I'll accept PRs.
This should work:
ShallowRenderer.findAllWithType(component, TestTwo)
There's not much documentation on the shallow rendering stuff but in the rendered tree it gives you back each element has a type property. If the element was a composite component like your TestTwo, the type is the Function that is returned from React.createClass (or the class if you're using ES2015 classes). If the element was a DOM element then type will be just a String, e.g, 'div' or 'span'.
Given that, I didn't have separate functions for DOM components and composite components like the normal React TestUtils. However, I can if you think it would simplify the meaning?
Thank you/ I'll check that out and maybe submit a PR with some tests/examples.
How about using displayName when type is a Function?
It also seems to me that Function is sometimes named (possibly in ES6 case), so that could also be checked.
Be great to see this working. Currently we use a lot of functional components which don't get found using this method.