diff --git a/src/reducers/__tests__/objectReducer.test.js b/src/reducers/__tests__/objectReducer.test.js index 2a60c52..cfca9cf 100644 --- a/src/reducers/__tests__/objectReducer.test.js +++ b/src/reducers/__tests__/objectReducer.test.js @@ -17,8 +17,8 @@ describe('ObjectReducer', () => { it('reducer should return the state if the payload is undefined', () => { expect(replace.reducer({ foo: 1 }, undefined)).toEqual({ foo: 1 }); }); - it('reducer should return the new state', () => { - expect(replace.reducer({ foo: 1 }, { foo: 2 })).toEqual({ foo: 2 }); + it('reducer should return the new state combined with the initial state', () => { + expect(replace.reducer({ foo: 1, bar: 3 }, { foo: 2 }, { foo: 1, bar: 5 })).toEqual({ foo: 2, bar: 5 }); }); }); diff --git a/src/reducers/objectReducer.js b/src/reducers/objectReducer.js index 324341d..9d589a9 100644 --- a/src/reducers/objectReducer.js +++ b/src/reducers/objectReducer.js @@ -73,9 +73,12 @@ export const DEFAULT_SHAPE_BEHAVIORS: ShapeReducerBehaviorsConfig = { validate: false, }, replace: { - reducer(state, payload) { + reducer(state, payload, initialState) { if (!payload) return state; - return payload; + return { + ...initialState, + ...payload, + }; }, validate: true, }