Redux warning appears only in tests

I created a game with tic tac toe with reactive reduction.

I am using create-react-app .

I have the following repository:

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 works as I expect. Unless I run 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 that I have, I don’t even test the store. Therefore, I think this happens when compiling the code. I tried to put console.log(gameStatusReducer)in front of the root gear line. It shows that gameStatusReducer is undefined.

gameSettingsReducer, gameStatusReducer , , , , . . , , .

, :

  • ?
  • , ?
+4
3

.

: export gameStateReducer default import { gameStateReducer } from // ....

Jest , -, , - , react-create-app .

, Jest (, ), , .

: --testPathPattern npm test script, .test.js, , .

: , , , ( , , import). , combineReducers, , - , . :

gameStatus: gameStatusReducer || (() => ())

... , , - import Jest/babel-jest.

, Jest , , Jest . Jest, react-create-app.

!

+8

, TypeScript.

, No reducer provided for key "favourites".

, , -, , , .

favourites Redux .

- , , Store.getState().someOtherReducersState, .

, jest.mock('../route/to/Store'); , .

+2

, import { combineReducers } from 'redux'; , createStore.

:

    const appReducer = combineReducers({
      gameSettings: ...,
      gameStatus: ...,
    });

  const store = createStore(
    appReducer,
    enhancer,
  );
-2

Source: https://habr.com/ru/post/1674682/


All Articles