我有减速器的单元测试,我应该是这样.但是,当我在浏览器中进行调试时,我想检查我的动作是否被正确调用,以及是否相应地修改了状态.
我正在寻找像:
window._redux.store
…在浏览器中,所以我可以在控制台上输入,并检查事情发生.
我该如何实现呢?
解决方法
您可以使用日志记录中间件
as described in the Redux Book:
/** * Logs all actions and states after they are dispatched. */ const logger = store => next => action => { console.group(action.type) console.info('dispatching',action) let result = next(action) console.log('next state',store.getState()) console.groupEnd(action.type) return result } let createStoreWithMiddleware = applyMiddleware(logger)(createStore) let yourApp = combineReducers(reducers) let store = createStoreWithMiddleware(yourApp)
或者,您可以将日志记录更改为仅附加到全局数组(您的window._redux),并且可以在需要特定状态信息时查看数组.