Skip to content

Commit

Permalink
fix: show module path when it overwrite a state field
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Nov 10, 2019
1 parent 62e05cc commit b049121
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')}"`
)
}
}
Expand Down
18 changes: 11 additions & 7 deletions test/unit/modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
)
})

Expand Down

0 comments on commit b049121

Please sign in to comment.