Add test for missing method
This commit is contained in:
parent
2b0ccfb984
commit
daf32de431
@ -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,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
@ -71,11 +71,14 @@ export function createReducer<ActionType extends string, State extends IState>(
|
||||
handlers: TReduxHandlers<R, State>,
|
||||
) {
|
||||
return self.withHandler<R>((state, action) => {
|
||||
if (action.method in handlers) {
|
||||
const newState = handlers[action.method](state, action)
|
||||
return {
|
||||
...state,
|
||||
...newState,
|
||||
}
|
||||
}
|
||||
return state
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user