Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/combineReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export default function combineReducers(reducers) {
var finalReducers = {}
for (var i = 0; i < reducerKeys.length; i++) {
var key = reducerKeys[i]
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
warning(`No reducer provided for key "${key}"`)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Do you mind adding newlines before and after this new block? It makes it easier to spot the dev-only code.

if (typeof reducers[key] === 'function') {
finalReducers[key] = reducers[key]
}
Expand Down
18 changes: 18 additions & 0 deletions test/combineReducers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ describe('Utils', () => {
).toEqual([ 'stack' ])
})

it('warns if a reducer prop is undefined', () => {
const spy = expect.spyOn(console, 'error')

let isNotDefined
combineReducers({ isNotDefined })
expect(spy.calls[0].arguments[0]).toMatch(
/No reducer provided for key "isNotDefined"/
)

spy.reset()
combineReducers({ thing: undefined })
expect(spy.calls[0].arguments[0]).toMatch(
/No reducer provided for key "thing"/
)

spy.restore()
})

it('throws an error if a reducer returns undefined handling an action', () => {
const reducer = combineReducers({
counter(state = 0, action) {
Expand Down