Skip to content

Commit 4b6047c

Browse files
committed
Warn when reducer is not a function
1 parent b02310b commit 4b6047c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/combineReducers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export default function combineReducers(reducers) {
121121
if (process.env.NODE_ENV !== 'production') {
122122
if (typeof reducers[key] === 'undefined') {
123123
warning(`No reducer provided for key "${key}"`)
124+
} else if (typeof reducers[key] !== 'function') {
125+
warning(`"${key}" is not a function`)
124126
}
125127
}
126128

test/combineReducers.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ describe('Utils', () => {
196196
console.error = preSpy
197197
})
198198

199+
it('warns if a reducer is not a function', () => {
200+
const preSpy = console.error
201+
const spy = jest.fn()
202+
console.error = spy
203+
204+
let isFunction = state => state
205+
let isNotFunction = 'isNotFunction'
206+
combineReducers({ isFunction, isNotFunction })
207+
expect(spy.mock.calls[0][0]).toMatch(
208+
/"isNotFunction" is not a function/
209+
)
210+
211+
spy.mockClear()
212+
isNotFunction = []
213+
combineReducers({ isFunction, isNotFunction })
214+
expect(spy.mock.calls[0][0]).toMatch(
215+
/"isNotFunction" is not a function/
216+
)
217+
218+
spy.mockClear()
219+
console.error = preSpy
220+
})
221+
199222
it('warns if input state does not match reducer shape', () => {
200223
const preSpy = console.error
201224
const spy = jest.fn()

0 commit comments

Comments
 (0)