diff --git a/src/module/module-collection.js b/src/module/module-collection.js index 095872882..75e641fce 100644 --- a/src/module/module-collection.js +++ b/src/module/module-collection.js @@ -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 } } diff --git a/test/unit/module/module-collection.spec.js b/test/unit/module/module-collection.spec.js index 3e8081ce3..85298c086 100644 --- a/test/unit/module/module-collection.spec.js +++ b/test/unit/module/module-collection.spec.js @@ -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) + }) })