我试图使用jest-cli测试一个反应组件是否包含其输出中的另一个组件.我无法想出如何做到这一点.
这是我的组件:
DesignerPage组件
[...] 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组件
/** @jsx React.DOM */ var React = require("react"); var TopBar = React.createClass({ render: function() { return ( <nav className="top-bar"> </nav> ); } }); module.exports = TopBar;
现在,我想测试DesignerPage组件是否包含TopBar组件.这是我认为应该工作的:
/** @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); }); });
但它不通过…