diff --git a/src/reducers/services.js b/src/reducers/services.js index 2925ea821c..3d44ee3587 100644 --- a/src/reducers/services.js +++ b/src/reducers/services.js @@ -29,10 +29,8 @@ function fetchStarted(state) { } function fetchServicesDone(state, { payload }) { - const services = payload.data; - if (Array.isArray(services)) { - services.sort(baseStringComparator); - } + const services = payload.data || []; + services.sort(baseStringComparator); return { ...state, services, error: null, loading: false }; } diff --git a/src/reducers/services.test.js b/src/reducers/services.test.js index 9ef1e274da..d2f49bcb62 100644 --- a/src/reducers/services.test.js +++ b/src/reducers/services.test.js @@ -29,6 +29,20 @@ function verifyInitialState() { beforeEach(verifyInitialState); afterEach(verifyInitialState); +it('#92 - ensures services is at least an empty array', () => { + const services = null; + const state = serviceReducer(initialState, { + type: `${fetchServices}_FULFILLED`, + payload: { data: services }, + }); + expect(state).toEqual({ + services: [], + operationsForService: {}, + loading: false, + error: null, + }); +}); + it('should handle a fetch services with loading state', () => { const state = serviceReducer(initialState, { type: `${fetchServices}_PENDING`,