尝试在react / redux套件中运行测试后,我收到以下错误。我确保我使用redux-immutable
作为回购时的文档建议,但无济于事。
The initialState argument passed to createStore is of unexpected type. Expected argument to be an instance of Immutable.Collection or Immutable.Record with the following properties:
我正在使用Immutable.JS()
import { combineReducers } from 'redux-immutable';
import dashboard from '../Dashboard';
import budget from '../Budget';
import { reducer as formReducer } from 'redux-form/immutable';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
const rootReducer = combineReducers({
form: formReducer,
dashboard,
budget
});
export default rootReducer;
import {createStore, applyMiddleware, compose} from 'redux';
import thunk from 'redux-thunk';
import reducers from './reducers';
export function configureStore(){
// Use redux dev tools if available, otherwise use default composition;
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducers, {}, composeEnhancers(
applyMiddleware(thunk)
));
return store;
}
我在store
文件中尝试过以下操作,因为我不知道错误是什么,但它仍然无效。
const store = createStore(reducers, Immutable.collection({form: "", dashboard: "", budget: ""}), composeEnhancers(
applyMiddleware(thunk)
));
我也尝试了以下内容:
https://github.com/gajus/redux-immutable
const store = createStore(reducers, Immutable.Map(), composeEnhancers(
applyMiddleware(thunk)
));
我尝试制作一个记录不可变对象
const StateRecord = Immutable.Record({
"form": "form",
"dashboard": "dashboard",
"budget": "budget"
});
const store = createStore(reducers, StateRecord, composeEnhancers(
applyMiddleware(thunk)
));
答案 0 :(得分:2)
不幸的是,我应该提供我的测试运行器,因为它是问题的根源。将新提供程序呈现到我的组件中..
<Provider store={createStore(reducers, Immutable.fromJS(state))}>
<ComponentClass {...props} />
</Provider>
看起来像
<Provider store={createStore(reducers, (state))}>
<ComponentClass {...props} />
</Provider>