首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React/Redux测试错误:传递给createStore的initialState参数属于意外类型

React/Redux测试错误:传递给createStore的initialState参数属于意外类型
EN

Stack Overflow用户
提问于 2018-01-10 01:59:55
回答 1查看 403关注 0票数 2

在我尝试在react/redux套件中运行测试后,我得到了以下错误。我已经确保按照文档中的建议使用redux-immutable,但无济于事。

代码语言:javascript
复制
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()

Reducers文件:

代码语言:javascript
复制
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;

存储文件

代码语言:javascript
复制
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文件中尝试了以下操作,因为我不知道错误是什么,但仍然不起作用。

代码语言:javascript
复制
  const store = createStore(reducers, Immutable.collection({form: "", dashboard: "", budget: ""}), composeEnhancers(
    applyMiddleware(thunk)
  ));

我还尝试了以下几种方法:

https://github.com/gajus/redux-immutable

代码语言:javascript
复制
  const store = createStore(reducers, Immutable.Map(), composeEnhancers(
    applyMiddleware(thunk)
  ));

我尝试创建一个记录不可变的对象。

代码语言:javascript
复制
  const StateRecord = Immutable.Record({
    "form": "form",
    "dashboard": "dashboard",
    "budget": "budget"
  });

  const store = createStore(reducers, StateRecord, composeEnhancers(
    applyMiddleware(thunk)
  ));
EN

回答 1

Stack Overflow用户

发布于 2018-01-10 02:22:03

不幸的是,我应该提供我的测试运行程序,因为它是问题的根源。将新的提供程序呈现到我的组件中..

测试运行器代码段

代码语言:javascript
复制
<Provider store={createStore(reducers, Immutable.fromJS(state))}>
  <ComponentClass {...props} />
</Provider>

最初看起来像什么?

代码语言:javascript
复制
<Provider store={createStore(reducers, (state))}>
  <ComponentClass {...props} />
</Provider>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48174144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档