簡體   English   中英

測試 redux-mock-store 時分派動作后的最終狀態為空

[英]Final state after dispatching action is empty while testing redux-mock-store

我正在使用redux-mock-store來測試我的 redux 操作。 但是,我想測試我的操作以及設置它們的商店。 我的代碼是這樣的:

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

但是我的 finalState 是empty ,我知道沒有減速器在監聽我的動作並且狀態沒有得到更新。 但我想在一個地方用動作來測試我的狀態。 有什么方法可以集成它,或者有其他一些 npm 模塊可以提供它嗎?

編輯:

我想在一個地方測試我的storeactions 有沒有辦法做到這一點? 我應該還是不應該這樣做?

來自redux-mock-store的文檔:

請注意,該庫旨在測試與動作相關的邏輯,而不是與減速器相關的邏輯。 換句話說,它不會更新 Redux 存儲。 如果您想要將操作和化簡器組合在一起的復雜測試,請查看其他庫(例如, redux-actions-assertions )。 有關更多詳細信息,請參閱問題#71

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM