Skip to content

Commit

Permalink
Check existence of module parent in isRegistered (fix #1850)
Browse files Browse the repository at this point in the history
  • Loading branch information
urbnjamesmi1 committed Oct 16, 2020
1 parent 6b0014c commit 93967bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/module/module-collection.js
Expand Up @@ -72,7 +72,11 @@ export default class ModuleCollection {
const parent = this.get(path.slice(0, -1))
const key = path[path.length - 1]

return parent.hasChild(key)
if (parent) {
return parent.hasChild(key)
}

return false
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/module/module-collection.spec.js
Expand Up @@ -100,4 +100,18 @@ describe('ModuleCollection', () => {
collection.unregister(['a'])
expect(spy).toHaveBeenCalled()
})

it('isRegistered', () => {
const collection = new ModuleCollection({})
collection.register(['a'], {
state: { value: true }
})
collection.register(['a', 'b'], {
state: { value: false }
})
expect(collection.isRegistered(['a'])).toBe(true)
expect(collection.isRegistered(['a', 'b'])).toBe(true)
expect(collection.isRegistered(['c'])).toBe(false)
expect(collection.isRegistered(['c', 'd'])).toBe(false)
})
})

0 comments on commit 93967bc

Please sign in to comment.