Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check existence of module parent in isRegistered (fix #1850) #1851

Merged
merged 2 commits into from Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})