From 96d6033ccf78a8cd8768a321d1dd99bd5d99779e Mon Sep 17 00:00:00 2001 From: CzBiX Date: Wed, 16 Oct 2019 18:10:08 +0800 Subject: [PATCH] Fix update config store --- src/store/config.ts | 2 +- tests/unit/store/config.spec.ts | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/store/config.ts b/src/store/config.ts index 8c00870..86688a0 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -40,7 +40,7 @@ export const configStore : Module = { updateConfig(state, payload) { const { key, value } = payload; if (_.isPlainObject(value)) { - const tmp = _.merge({}, state.userConfig, value); + const tmp = _.merge({}, state.userConfig[key], value); Vue.set(state.userConfig, key, tmp); } else { Vue.set(state.userConfig, key, value); diff --git a/tests/unit/store/config.spec.ts b/tests/unit/store/config.spec.ts index 7e1182b..d98185d 100644 --- a/tests/unit/store/config.spec.ts +++ b/tests/unit/store/config.spec.ts @@ -53,19 +53,30 @@ describe('update config', () => { }); test('update object', () => { + const value1 = { + foo1: 'bar1', + }; + store.commit('updateConfig', { key: 'obj', - value: { - foo: 'bar', - }, + value: value1, }); - expect(store.getters.config).toMatchObject({ - obj: { - foo: 'bar', - }, + expect(store.state.config.userConfig).toEqual({ + obj: value1, + }); + + const value2 = { + foo2: 'bar2', + }; + store.commit('updateConfig', { + key: 'obj', + value: value2, + }); + + expect(store.state.config.userConfig).toEqual({ + obj: Object.assign({}, value1, value2), }); - expect(spySet).toBeCalled(); }); test('update plain type', () => {