Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix: stop throwing an error on `hasModule` when parent does not exists (
- Loading branch information
|
@@ -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 |
|
|
} |
|
|
} |
|
|
|
|
|
|
@@ -81,6 +81,23 @@ describe('ModuleCollection', () => { |
|
|
expect(collection.get(['a'])).toBe(undefined) |
|
|
}) |
|
|
|
|
|
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) |
|
|
}) |
|
|
|
|
|
it('does not unregister initial modules', () => { |
|
|
const collection = new ModuleCollection({ |
|
|
modules: { |
|
|
|
@@ -91,6 +91,18 @@ describe('Modules', () => { |
|
|
expect(store.hasModule('bonjour')).toBe(false) |
|
|
}) |
|
|
|
|
|
it('dynamic module existance test with nested modules', () => { |
|
|
const store = new Vuex.Store({}) |
|
|
|
|
|
store.registerModule('a', {}) |
|
|
store.registerModule(['a', 'b'], {}) |
|
|
|
|
|
expect(store.hasModule(['a'])).toBe(true) |
|
|
expect(store.hasModule(['a', 'b'])).toBe(true) |
|
|
expect(store.hasModule(['c'])).toBe(false) |
|
|
expect(store.hasModule(['c', 'd'])).toBe(false) |
|
|
}) |
|
|
|
|
|
it('dynamic module registration preserving hydration', () => { |
|
|
const store = new Vuex.Store({}) |
|
|
store.replaceState({ a: { foo: 'state' }}) |
|
|