From daf32de431804fcae3bcf897a35b62ca07ec3c1c Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Thu, 1 Aug 2019 19:55:30 +0700 Subject: [PATCH] Add test for missing method --- packages/jsonrpc/src/redux.test.ts | 11 +++++++++++ packages/jsonrpc/src/redux.ts | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/jsonrpc/src/redux.test.ts b/packages/jsonrpc/src/redux.test.ts index 3fc0f71..02e20f5 100644 --- a/packages/jsonrpc/src/redux.test.ts +++ b/packages/jsonrpc/src/redux.test.ts @@ -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, + }) + }) + }) }) }) diff --git a/packages/jsonrpc/src/redux.ts b/packages/jsonrpc/src/redux.ts index 2af815a..e2caf63 100644 --- a/packages/jsonrpc/src/redux.ts +++ b/packages/jsonrpc/src/redux.ts @@ -71,11 +71,14 @@ export function createReducer( handlers: TReduxHandlers, ) { return self.withHandler((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 }) }, }