我正在尝试使用 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 行有什么问题。如果我取消注释行,我会在注释中显示错误。
// Error: Did not find exactly one match for componentType:function ModalHeader()...
//var headerComponent = TestUtils.findRenderedComponentWithType(component, ReactBootstrap.Modal.Header);
//expect(headerComponent).not.toBe(null);
根据测试实用程序的最新官方文档(链接),您应该将 ReactComponent 作为第一个参数传递。
有人能告诉我出了什么问题吗?