based on this comment and this thread, starting this thread to discuss how to test components with 'render callbacks'.
Consider the following 'app'.
class Double{
render(){
return this.props.children(this.props.value * 2);
}
}
class App extends React.Component{
render(){
return <Double value={this.props.input}>{
doubled => <div>{doubled}</div>
}</A>;
}
}
React.render(<App input={10}/>, el); // will output '20', as expected
Now, if we wanted to test this, we could write something like -
var stateful = TestUtils.renderIntoDocument(<App input={50}/>);
var div = TestUtils.findRenderedDOMComponentWithTag(stateful, 'div');
div.getDOMNode().textContent.should.eql('100');
However, we can't test beyond the callback boundary with ReactShallowRenderer.
// this doesn't work, of course
TestUtils.createRenderer().render(<App input={50}/>).getRenderOutput()
.should.eql(<Double value={this.props.input}>
<div>{100}</div>
</A>)
Unclear how to approach this, frankly. Should ShallowRenderer 'recognize' components like this? Or should they be marked with a flag? (this.rendersCallback = true ?). The only workaround for now is to not use the ShallowRenderer :(
/cc @pspeter3
based on this comment and this thread, starting this thread to discuss how to test components with 'render callbacks'.
Consider the following 'app'.
Now, if we wanted to test this, we could write something like -
However, we can't test beyond the callback boundary with
ReactShallowRenderer.Unclear how to approach this, frankly. Should ShallowRenderer 'recognize' components like this? Or should they be marked with a flag? (this.rendersCallback = true ?). The only workaround for now is to not use the ShallowRenderer :(
/cc @pspeter3