I'm writing tests for my react application. But when I try to render a nested component, then I got the error TitleBar is not defined and the test fails.
jest.dontMock('FUW.js');
jest.dontMock('TitleBar.js');
var React = require('react/addons');
var TitleBar = require('../js/components/TitleBar.js');
var FirstUseWindow = require('../js/components/windows/FirstUseWindow.js');
var TestUtils = React.addons.TestUtils;
describe('First use wizard', function(){
afterEach(function(done){//cleanup the DOM
React.unmountComponentAtNode(document.body);
setTimeout(done);
});
var FirstUseWindowElement = TestUtils.renderIntoDocument(
<div>
<FirstUseWindow />
</div>
);
});
The FirstUseWindow contains a TitleBar element which causes the error.
FUW.js
if (React === undefined) {
var React = require('react/addons');
}
var FirstUseWindow = React.createClass({
firstUseComplete:function(){
},
render:function(){
return(
<div>
<TitleBar text="tested" />
</div>
);
}
});
if (module !== undefined) {
module.exports = FirstUseWindow;
}
TitleBar.js
if (React === undefined) {
var React = require('react/addons');
}
var TitleBar = React.createClass({
render:function(){
return(
<header className="bar bar-nav">
<h1 className="title">{this.props.text}</h1>
</header>
);
}
});
if (module != undefined) {
module.exports = TitleBar;
}