Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/combineReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export default function combineReducers(reducers) {
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
warning(`No reducer provided for key "${key}"`)
} else if (typeof reducers[key] !== 'function') {
warning(`The reducer for "${key}" is not a function`)
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/combineReducers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,31 @@ describe('Utils', () => {
console.error = preSpy
})

it('warns if a reducer is not a function', () => {
const preSpy = console.error
const spy = jest.fn()
console.error = spy

let isFunction = state => null
let isNotFunction = 'isNotFunction'
let reducer = combineReducers({ isFunction, isNotFunction })
reducer({})
expect(spy.mock.calls[0][0]).toMatch(
/The reducer for "isNotFunction" is not a function/
)

spy.mockClear()
isNotFunction = []
reducer = combineReducers({ isFunction, isNotFunction })
reducer({})
expect(spy.mock.calls[0][0]).toMatch(
/The reducer for "isNotFunction" is not a function/
)

spy.mockClear()
console.error = preSpy
})

it('warns if input state does not match reducer shape', () => {
const preSpy = console.error
const spy = jest.fn()
Expand Down