Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaceReducer() should throw if argument is not a function #1321

Merged
merged 1 commit into from
Jan 30, 2016
Merged
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
4 changes: 4 additions & 0 deletions src/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export default function createStore(reducer, initialState, enhancer) {
* @returns {void}
*/
function replaceReducer(nextReducer) {
if (typeof nextReducer !== 'function') {
throw new Error('Expected the nextReducer to be a function.')
}

currentReducer = nextReducer
dispatch({ type: ActionTypes.INIT })
}
Expand Down
12 changes: 12 additions & 0 deletions test/createStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,16 @@ describe('createStore', () => {
createStore(reducers.todos, {})
).toNotThrow()
})

it('throws if nextReducer is not a function', () => {
const store = createStore(reducers.todos)

expect(() =>
store.replaceReducer()
).toThrow('Expected the nextReducer to be a function.')

expect(() =>
store.replaceReducer(() => {})
).toNotThrow()
})
})