Javascript ReduxForm需要存储作为测试道具通过
我正在尝试使用ReduxForm进行一些单元测试,很明显,像这样最简单的单元测试存在问题 实际上,我有一个搜索栏,当我修改它的输入时,我需要状态来反映数据 我编写了以下测试:Javascript ReduxForm需要存储作为测试道具通过,javascript,reactjs,redux,react-redux,redux-form,Javascript,Reactjs,Redux,React Redux,Redux Form,我正在尝试使用ReduxForm进行一些单元测试,很明显,像这样最简单的单元测试存在问题 实际上,我有一个搜索栏,当我修改它的输入时,我需要状态来反映数据 我编写了以下测试: beforeEach(() => { const store = configureStore()({ searchBar:{ inputField:'' } }); searchBar = TestUtils.renderInt
beforeEach(() => {
const store = configureStore()({
searchBar:{
inputField:''
}
});
searchBar = TestUtils.renderIntoDocument(<SearchBar store={store}/>);
});
it('should have a form Field tag', () => {
const input = TestUtils.findRenderedComponentWithType(searchBar, Field);
expect(input).toBeTruthy();
});
beforeach(()=>{
const store=configureStore()({
搜索栏:{
输入字段:“”
}
});
searchBar=TestUtils.renderIntoDocument();
});
它('应该有一个表单字段标记',()=>{
const input=TestUtils.findRenderedComponentWithType(搜索栏,字段);
expect(input.toBeTruthy();
});
这应该检验这一点:
import React from 'react';
import { Field, reduxForm } from 'redux-form';
/**
* The seach bar component class definition
*/
class SearchBar extends React.Component {
/**
* Render the searchBar component
*/
render() {
return (
<form>
<Field name="inputField" component="input" type="text"/>
<button type="submit">Rechercher</button>
</form>
);
}
}
/**
* Decorate the form
*/
SearchBar = reduxForm({
form: 'searchBar'
})(SearchBar);
export default SearchBar;
从“React”导入React;
从“redux form”导入{Field,reduxForm};
/**
*seach bar组件类定义
*/
类SearchBar扩展了React.Component{
/**
*呈现搜索栏组件
*/
render(){
返回(
回收机
);
}
}
/**
*装饰表格
*/
SearchBar=reduxForm({
表格:'搜索栏'
})(搜索栏);
导出默认搜索栏;
但我抛出了以下错误:
Invariant Violation: Could not find "store" in either the context or props of "Connect(ConnectedField)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(ConnectedField)". in src/index.spec.js (line 3551)
不变冲突:在“Connect(ConnectedField)”的上下文或道具中找不到“store”。将根组件包装在中,或者将“store”作为prop显式传递给“Connect(ConnectedField)”。在src/index.spec.js中(第3551行)
即使我在我的组件中传递道具。。。(请参阅每次通话前的提示)
有什么想法吗?要测试redux表单,您需要一个redux商店和一个提供者 试着这样做:
searchBar=TestUtils.renderIntoDocument()代码>