From b049121e8711ad2bdb42e919d15676ee78161d09 Mon Sep 17 00:00:00 2001 From: ktsn Date: Sun, 10 Nov 2019 22:14:43 +0800 Subject: [PATCH] fix: show module path when it overwrite a state field --- src/store.js | 2 +- test/unit/modules.spec.js | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/store.js b/src/store.js index e9084b5d23..00caafabc5 100644 --- a/src/store.js +++ b/src/store.js @@ -318,7 +318,7 @@ function installModule (store, rootState, path, module, hot) { if (process.env.NODE_ENV !== 'production') { if (moduleName in parentState) { console.warn( - `[vuex] state field "${moduleName}" was overridden by a module with the same name` + `[vuex] state field "${moduleName}" was overridden by a module with the same name at "${path.join('.')}"` ) } } diff --git a/test/unit/modules.spec.js b/test/unit/modules.spec.js index 9186d8eda8..8d4b789047 100644 --- a/test/unit/modules.spec.js +++ b/test/unit/modules.spec.js @@ -550,18 +550,22 @@ describe('Modules', () => { it('module: warn when module overrides state', () => { spyOn(console, 'warn') const store = new Vuex.Store({ - state () { - return { value: 1 } - }, modules: { - value: { - state: () => 2 + foo: { + state () { + return { value: 1 } + }, + modules: { + value: { + state: () => 2 + } + } } } }) - expect(store.state.value).toBe(2) + expect(store.state.foo.value).toBe(2) expect(console.warn).toHaveBeenCalledWith( - `[vuex] state field "value" was overridden by a module with the same name` + `[vuex] state field "value" was overridden by a module with the same name at "foo.value"` ) })