javascript - Test whether all reducers have been imported in the rootReducer -


i have rootreducer imports separate reducers so:

import { combinereducers } 'redux'; import departments './departments'; import indicators './indicators'; import versions './versions'; import projects './projects';  // combine reducers single reducer, state linked reducer via key used here const rootreducer = combinereducers({   versions,   departments,   indicators,   projects, });  export default rootreducer; 

since it's important reducer import everything, think makes sense test whether defined reducers in ./src/reducers imported. method can think of use fs check number of files in ./src/reducers (without index, or rootreducer) , check whether rootreducer contains many reducers.

seems ugly test, , bit fragile well. still nice notified failing test when forget include reducer. best way test whether reducers have been imported?

i hear you're coming don't think want dealing issue in tests. application grows you're want deeper reducer tree. e.g. projects reducer may come made of multiple sub-reducers , you'll have manage reducers need imported where. file system test become more , more brittle. in general, imports , file structures implementation details of project , want testing behavior of project.

but wanting immediate feedback on failing hook reducer totally makes sense. i'd try handle @ build level. assuming you're using webpack maybe see if this plugin can solve problem. detects unused exports. add plugins

new unusedfileswebpackplugin({ pattern: 'src/reducers/**' }) 

and build warn when have file isn't being imported. since works modules won't have worry directory structure (beyond ensuring pattern matches files want check).


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -