I've been trying to figure out why this isn't working for a few days. I am having a really hard time getting reactjs TestUtils to work even when I reduced it to the most simple of examples:
describe('Layout', function() {
it('try to find className', function(done) {
var Wrapper = React.createClass({
render: function() {
return <div className="testWrapper">Hello <span>Jim</span></div>;
}
});
var TestWrap = React.createClass({
render() {
return (
<div>
<p>Test this </p>
<Wrapper />
</div>
);
}
})
var renderedTree = TestUtils.renderIntoDocument(<TestWrap />);
var renderedMyComponent = TestUtils.findRenderedDOMComponentWithTag(renderedTree, 'div');
done();
});
I am getting this error:
Error: Did not find exactly one match for tag:div
at Object.ReactTestUtils.findRenderedDOMComponentWithTag (/Users/bli1/Development/QE/data-trader/data-trader/spec/views/layout.js:22398:14)
at Context.<anonymous> (/Users/bli1/Development/QE/data-trader/data-trader/spec/views/layout.js:148:46)
Chrome 44.0.2403 (Mac OS X 10.10.4): Executed 1 of 1 (1 FAILED) ERROR (0.041 secs / 0.007 secs)
Now when I change to look for span, it works...
Same code but replace
var renderedMyComponent = TestUtils.findRenderedDOMComponentWithTag(renderedTree, 'div');
with
var renderedMyComponent = TestUtils.findRenderedDOMComponentWithTag(renderedTree, 'span');
result:
Executed 1 of 1 SUCCESS (0.039 secs / 0.007 secs)
TestUtils.scryRenderedDOMComponentsWithTag()? I can't help but notice your example contains twodivs and that would violate the find function's assumption that there's only one result.console.log()is actually causing the error. Would you know why? Also, youre correct about the multipledivs