【发布时间】:2016-02-12 20:01:24
【问题描述】:
我正在尝试使用 Jasmine 对 React Bootstrap 模式对话框进行单元测试。但它没有按预期工作。
这里是使用最新版本的 React、React Bootstrap、Jasmine 的 jsfiddle 链接。:http://jsfiddle.net/30qmcLyf/3/
测试失败:
第 27-28 行
// This test fails. Find DOM Node.
var instanceDomNode = ReactDOM.findDOMNode(instance);
expect(instanceDomNode).not.toBe(null);
第 39-40 行
//This test fails. Find modal header.
var headerComponents = TestUtils.scryRenderedComponentsWithType(component, ReactBootstrap.Modal.Header);
expect(headerComponents.length).not.toBe(0);
#35-36 行还有什么问题。如果我取消注释行,我会在 cmets 中显示错误。
// Error: Did not find exactly one match for componentType:function ModalHeader()...
//var headerComponent = TestUtils.findRenderedComponentWithType(component, ReactBootstrap.Modal.Header);
//expect(headerComponent).not.toBe(null);
根据测试实用程序的最新官方文档 (link),您应该将 ReactComponent 作为第一个参数传递。
谁能告诉我怎么了?
【问题讨论】:
标签: unit-testing reactjs jasmine react-bootstrap