Add test for missing method

This commit is contained in:
Jerko Steiner 2019-08-01 19:55:30 +07:00
parent 2b0ccfb984
commit daf32de431
2 changed files with 18 additions and 4 deletions

View File

@ -227,6 +227,17 @@ describe('createReduxClient', () => {
expect(store.getState().handler.error).toMatch(/status code 500/)
})
})
describe('action with missing method', () => {
it('does not fail when action not defined', () => {
const {store} = getClient()
store.dispatch({
type: 'myService',
method: 'missingMethod',
status: 'resolved',
payload: null,
})
})
})
})
})

View File

@ -71,11 +71,14 @@ export function createReducer<ActionType extends string, State extends IState>(
handlers: TReduxHandlers<R, State>,
) {
return self.withHandler<R>((state, action) => {
const newState = handlers[action.method](state, action)
return {
...state,
...newState,
if (action.method in handlers) {
const newState = handlers[action.method](state, action)
return {
...state,
...newState,
}
}
return state
})
},
}