I have created a tic tac toe game with react redux.
I am using create-react-app.
I have the following store:
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;
Everything runs as I expect. Except for when I am running tests (npm test
) the following appears in the console:
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.
In the few tests I have, I am not even testing the store. So I guess this comes up while compiling the code.
I tried putting console.log(gameStatusReducer)
before the root reducer line.
It shows that gameStatusReducer is undefined.
Since both the gameSettingsReducer and the gameStatusReducer are created in very similar ways, I do not know where this error comes from and do not even know how to investigate the issue further. This only shows up when running the tests. Running the app does not show this problem and the app works as expected.
So, the questions are:
- Why is this just showing up in the tests?
- How to investigate where the problem is coming from?
tree.test.js
or theboard.test.js
?npm test
which will start up jest and run all tests. There you can tell it to focus on a subset of the tests. Regardless of which subset the "console.error" message gets printed in the terminal.