I am trying to do some unit testing by using findRenderedComponentWithType
and findRenderedComponentWithType
to find components. However, I am having a bit of trouble.
I have a shallow rendered component <Layout />
and within it, I want to find <UserMenu />
.
var Layout = React.createClass({
render: function(){
console.log(this.props);
return (
<div id="data-trader">
<header className="header">
<UserMenu user={this.props.user} />
</header>
<SideMenu user={this.props.user}/>
</div>
);
}
});
module.exports = Layout;
Within my test file, I tried this:
describe('Layout', function() {
beforeEach(function(){
fakeDOM = TestUtils.createRenderer();
it('should exist as a component', function(done) {
expect(<Layout/>).to.exist;
done();
});
fakeDOM.render(<Layout />);
renderedFakeDOMOutput = fakeDOM.getRenderOutput();
});
it('should have login button when props.user is undefined', function(done) {
renderedFakeDOMOutput.props.user = undefined;
let UserMenuComponent = TestUtils.scryRenderedComponentsWithType(renderedFakeDOMOutput, UserMenu);
done();
});
});
However, scryRenderedComponentsWithType
and findRenderedComponentWithType
cannot find anything of the components with the type UserMenu
.
I also tried to create another file where it exports
the UserMenu
component but I get the same output or 0 found (Array length 0) or error when no components are found (Error: Did not find exactly one match for componentType:function UserMenu()
).