I'm trying to use jest-cli to test whether one react component contains another component in it's output. I'm having trouble figuring out how to do this.
Here are my components:
DesignerPage Component
[...]
var TopBar = require('../components/layout/TopBar.js');
var DesignerPage = React.createClass({
getInitialState: function() {
var state = {
};
return state;
},
render: function() {
return (
<div>
<TopBar />
</div>
)
}
});
module.exports = DesignerPage;
TopBar Component
/** @jsx React.DOM */
var React = require("react");
var TopBar = React.createClass({
render: function() {
return (
<nav className="top-bar">
</nav>
);
}
});
module.exports = TopBar;
Now, I want to test whether the DesignerPage component contains the TopBar component. Here is what I think should work:
/** @jsx React.DOM */
jest.dontMock('../../src/js/pages/DesignerPage.js');
describe('DesignerPage', function() {
it('should contain a TopBar', function() {
var React = require('react/addons');
var DesignerPage = require('../../src/js/pages/DesignerPage.js');
var TestUtils = React.addons.TestUtils;
// Render a DesignerPage into the document
var page = TestUtils.renderIntoDocument(
<DesignerPage />
);
// Verify that a TopBar is included
var topbar = TestUtils.scryRenderedComponentsWithType(page, 'TopBar');
expect(topbar.length).toBe(1);
});
});
But it doesn't pass... :(
$ ./node_modules/jest-cli/bin/jest.js DesignerPage
Found 1 matching test...
FAIL __tests__/pages/DesignerPage-test.js (4.175s)
● DesignerPage › it should contain a TopBar
- Expected: 0 toBe: 1
at Spec.<anonymous> (__tests__/pages/DesignerPage-test.js:16:27)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
1 test failed, 0 test passed (1 total)
Run time: 6.462s