我是React编程的新手。我正在为redux connect组件编写测试用例。所以我从不同的reducer那里接收 prop 。我使用jest和react测试库来编写测试用例。我使用redux-mock-store来模拟存储数据,但这不起作用。
TestComponent:
import customerInfo from './customerInfo.json'
import appInfo from './appInfo.json'
const middlewares = []
const mockStore = configureStore(middlewares)
const initialState = {
customerInfo:customerInfo,
appInfo:appInfo
}
let appStore = mockStore(initialState)
render(
<Provider store={appStore}>
<PersistGate loading={null} persistor={persistor}>
<Router history={newHistory}>
<Home/>
</Router>
</PersistGate>
</Provider>
);
HomeComponent:
<Home/>
const mapStateToProps = (state) => {
return {
appInfo: state.appReducer.appInfo,
customerInfo: state.userReducer.customerInfo
};
};
1条答案
按热度按时间lyr7nygr1#
您没有为
mockStore
函数提供正确的初始状态。它应该是:
一个完整的例子:
测试结果: