Skip to content

Commit

Permalink
fix: warn when unregistering non existing module
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Jun 29, 2020
1 parent 04e2bd8 commit 626b1de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/module/module-collection.js
Expand Up @@ -49,7 +49,20 @@ export default class ModuleCollection {
unregister (path) {
const parent = this.get(path.slice(0, -1))
const key = path[path.length - 1]
if (!parent.getChild(key).runtime) return

if (!parent.getChild(key)) {
if (__DEV__) {
console.warn(
`[vuex] trying to unregister module '${key}', which is ` +
`not registered`
)
}
return
}

if (!parent.getChild(key).runtime) {
return
}

parent.removeChild(key)
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/module/module-collection.spec.js
Expand Up @@ -92,4 +92,12 @@ describe('ModuleCollection', () => {
collection.unregister(['a'])
expect(collection.get(['a']).state.value).toBe(true)
})

it('warns when unregistering non existing module', () => {
const spy = jest.spyOn(console, 'warn').mockImplementation()

const collection = new ModuleCollection({})
collection.unregister(['a'])
expect(spy).toHaveBeenCalled()
})
})

0 comments on commit 626b1de

Please sign in to comment.