私はreact reduxでtic tac toeゲームを作成しました。テストでのみ表示されるRedux警告
私はcreate-react-appを使用しています。
私は、次の店を持っている:私は期待どおり
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'ですか? –