我已经创建了一个tic tac toe游戏,带有reactx。我正在使用create-react-app。Redux警告只出现在测试中
我有以下的店铺:
import {createStore, combineReducers} from 'redux';
import gameSettingsReducer from './reducers/gameSettings.js';
import gameStatusReducer from './reducers/gameStatus.js';
const rootReducer = combineReducers({gameSettings: gameSettingsReducer,
gameStatus: gameStatusReducer});
export const defaultGameStatus = {
currentPlayerSymbol: "X",
turnNumber: 0,
currentView: "start-menu", //one of "start-menu", "in-game", "game-over"
winner: "draw", //one of "X", "O", "draw"
board: [["E", "E", "E"],
["E", "E", "E"],
["E", "E", "E"]],
lastMove: []
};
const store = createStore(rootReducer, {
gameSettings:{
playerSymbol: "X", //one of "X", "O"
difficulty: "easy" //one of "easy", "hard"
},
gameStatus: defaultGameStatus
});
export default store;
运行一切如我所料。除了当我运行测试(npm test
)以下为出现在控制台:
console.error node_modules\redux\lib\utils\warning.js:14
No reducer provided for key "gameStatus"
console.error node_modules\redux\lib\utils\warning.js:14
Unexpected key "gameStatus" found in preloadedState argument passed to createStore. Expected to find one of the known reducer keys instead: "gameSettings". Unexpected keys will be ignored.
在几个测试我有,我连测试商店。所以我猜这是在编译代码时出现的。 我试过在根减速线之前放console.log(gameStatusReducer)
。它显示gameStatusReducer是未定义的。
既然gameSettingsReducer和gameStatusReducer都是以非常相似的方式创建的,我不知道这个错误来自哪里,甚至不知道如何进一步调查问题。这只在运行测试时才显示出来。运行应用程序不会显示此问题,并且应用程序按预期工作。
所以,问题是:
- 为什么这只是显示在测试吗?
- 如何调查问题来自哪里?
向我们展示./reducers/gameStatus.js的代码,这可能是一个问题。 – Yuval
不知道我是否应该把所有这些代码放在这个问题中:https://github.com/zelite/tic-tac-toe/blob/master/src/reducers/gameStatus.js就像我说的,错误只出现在测试中。在浏览器中正常运行应用程序时,减速器正常工作。 – zelite
它给你什么问题?那是'tree.test.js'还是'board.test.js'? –