Skip to content

Commit 93967bc

Browse files
committed
Check existence of module parent in isRegistered (fix #1850)
1 parent 6b0014c commit 93967bc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/module/module-collection.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export default class ModuleCollection {
7272
const parent = this.get(path.slice(0, -1))
7373
const key = path[path.length - 1]
7474

75-
return parent.hasChild(key)
75+
if (parent) {
76+
return parent.hasChild(key)
77+
}
78+
79+
return false
7680
}
7781
}
7882

test/unit/module/module-collection.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,18 @@ describe('ModuleCollection', () => {
100100
collection.unregister(['a'])
101101
expect(spy).toHaveBeenCalled()
102102
})
103+
104+
it('isRegistered', () => {
105+
const collection = new ModuleCollection({})
106+
collection.register(['a'], {
107+
state: { value: true }
108+
})
109+
collection.register(['a', 'b'], {
110+
state: { value: false }
111+
})
112+
expect(collection.isRegistered(['a'])).toBe(true)
113+
expect(collection.isRegistered(['a', 'b'])).toBe(true)
114+
expect(collection.isRegistered(['c'])).toBe(false)
115+
expect(collection.isRegistered(['c', 'd'])).toBe(false)
116+
})
103117
})

0 commit comments

Comments
 (0)