Skip to content

Commit 17d80ff

Browse files
committed
test dynamic module registration (fix vuejs#243)
1 parent 6a0e430 commit 17d80ff

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Store {
6363
}
6464

6565
module (path, module, hot) {
66+
this._committing = true
6667
if (typeof path === 'string') path = [path]
6768
assert(Array.isArray(path), `module path must be a string or an Array.`)
6869

@@ -99,6 +100,7 @@ class Store {
99100
this.module(path.concat(key), modules[key], hot)
100101
})
101102
}
103+
this._committing = false
102104
}
103105

104106
mutation (type, handler, path = []) {

test/unit/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ describe('Vuex', () => {
191191
expect(store.getters.hasAny).to.equal(true)
192192
})
193193

194+
it('dynamic module registration', () => {
195+
const store = new Vuex.Store({
196+
strict: true
197+
})
198+
expect(() => {
199+
store.module('hi', {
200+
state: { a: 1 },
201+
mutations: { inc: state => state.a++ }
202+
})
203+
}).not.to.throw()
204+
expect(store.state.hi.a).to.equal(1)
205+
store.commit('inc')
206+
expect(store.state.hi.a).to.equal(2)
207+
})
208+
194209
it('store injection', () => {
195210
const store = new Vuex.Store()
196211
const vm = new Vue({

0 commit comments

Comments
 (0)