Testing Redux combined reducers

邮差的信 提交于 2019-12-09 17:07:29

问题


Say I have several reducer functions and I combine them all into one reducer using combineReducers(...), is there a way of testing what reducers the combined reducer actually contains?

For example, if I have this:

import { combineReducers } from 'redux'

const reducer1 = (state, action) => {...}
... (more reducers, etc)

const rootReducer = combineReducers({
    reducer1,
    reducer2,
    reducer3
})

export default rootReducer

Can I write a test with Mocha and Expect.js that will enable me to check if the rootReducer contains say reducer2? Is this even possible?

The way I currently have my project set up is that each reducer is in a separate file and is then imported into the file where the combineReducers(...) function is used to combine them all. I am testing all the individual reducers to check that they do what they should, but I also thought it would be a good idea to test the combined reducer to make sure that it contains all the other reducers that it should (in case I forget to add one for example).

Thanks


回答1:


You are testing the wrong thing IMO. You should trust that the combineReducers() function does what it should (it should be tested in Redux distrubution tests). But you can create a method that will return the object with reducers to combine to pass as the parameter to combineReducers(). That method can and should be tested.



来源:https://stackoverflow.com/questions/35800467/testing-redux-combined-reducers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!