【发布时间】:2018-05-04 13:30:23
【问题描述】:
ReferenceError:未定义窗口。当我运行 npm test 以开玩笑地进行单元测试时出现此错误。错误来自以下代码导出功能。有人遇到过这种错误并解决了吗?
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../modules/rootReducer';
export function injectAsyncReducers(asyncReducers) {
const injectReducers = Object.keys(asyncReducers).reduce((all, item) => {
if (store.asyncReducers[item]) {
delete all[item];
}
return all;
}, asyncReducers);
store.asyncReducers = Object.assign({}, store.asyncReducers, injectReducers);
replaceReducers(rootReducer);
}
【问题讨论】:
-
redux代码本身没有引用window。你的rootReducer是什么样的? -
这是我的 rootReducer 文件代码 import { combineReducers } from 'redux';从'../reducers/fetchMenu'导入菜单;从 '../reducers/chooseOrderType' 导入 orderType;从'../reducers/fetchVendorInfo'导入供应商;导出默认 combineReducers({ menu, vendor, orderType });
标签: reactjs react-native react-redux jestjs