[英]Final state after dispatching action is empty while testing redux-mock-store
I'm using redux-mock-store for testing my redux actions.我正在使用redux-mock-store来测试我的 redux 操作。 However, I want to test my actions and the store in which they're getting set.
但是,我想测试我的操作以及设置它们的商店。 My code goes something like this:
我的代码是这样的:
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
const mockStore = configureStore([thunk])
const store = mockStore({ ...state })
console.log(store.getState()) // => { ...state }
store.dispatch(someAction())
console.log(store.getActions()) // => [ someAction() ] The action does show up here!
console.log(store.getState()) // => { ...state } But this is the same unchanged state as above
But my finalState is empty
, I understand that no reducer is listening my action and the state is not getting updated.但是我的 finalState 是
empty
,我知道没有减速器在监听我的动作并且状态没有得到更新。 But I want to test my state with actions at one place.但我想在一个地方用动作来测试我的状态。 Is there any way to integrate that or there are some other npm module which provides that?
有什么方法可以集成它,或者有其他一些 npm 模块可以提供它吗?
Edit:编辑:
I want to test my store
and actions
at one place.我想在一个地方测试我的
store
和actions
。 Is there or is there not a way to do that?有没有办法做到这一点? Should I or should I not do that?
我应该还是不应该这样做?
From the doc of redux-mock-store :来自redux-mock-store的文档:
Please note that this library is designed to test the action-related logic, not the reducer-related one.
请注意,该库旨在测试与动作相关的逻辑,而不是与减速器相关的逻辑。 In other words, it does not update the Redux store.
换句话说,它不会更新 Redux 存储。 If you want a complex test combining actions and reducers together, take a look at other libraries (eg, redux-actions-assertions ).
如果您想要将操作和化简器组合在一起的复杂测试,请查看其他库(例如, redux-actions-assertions )。 Refer to issue #71 for more details.
有关更多详细信息,请参阅问题#71 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.