Skip to content

Commit e7a5e15

Browse files
up9cloudktsn
authored andcommitted
Add a testcase for mapGetters (with namespace and nested module) (#891)
1 parent ed13e4e commit e7a5e15

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test/unit/helpers.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,59 @@ describe('Helpers', () => {
251251
expect(vm.b).toBe(true)
252252
})
253253

254+
it('mapGetters (with namespace and nested module)', () => {
255+
const store = new Vuex.Store({
256+
modules: {
257+
foo: {
258+
namespaced: true,
259+
modules: {
260+
bar: {
261+
namespaced: true,
262+
state: { count: 0 },
263+
mutations: {
264+
inc: state => state.count++,
265+
dec: state => state.count--
266+
},
267+
getters: {
268+
hasAny: ({ count }) => count > 0,
269+
negative: ({ count }) => count < 0
270+
}
271+
},
272+
cat: {
273+
state: { count: 9 },
274+
getters: {
275+
count: ({ count }) => count
276+
}
277+
}
278+
}
279+
}
280+
}
281+
})
282+
const vm = new Vue({
283+
store,
284+
computed: {
285+
...mapGetters('foo/bar', [
286+
'hasAny',
287+
'negative'
288+
]),
289+
...mapGetters('foo', [
290+
'count'
291+
])
292+
}
293+
})
294+
expect(vm.hasAny).toBe(false)
295+
expect(vm.negative).toBe(false)
296+
store.commit('foo/bar/inc')
297+
expect(vm.hasAny).toBe(true)
298+
expect(vm.negative).toBe(false)
299+
store.commit('foo/bar/dec')
300+
store.commit('foo/bar/dec')
301+
expect(vm.hasAny).toBe(false)
302+
expect(vm.negative).toBe(true)
303+
304+
expect(vm.count).toBe(9)
305+
})
306+
254307
it('mapActions (array)', () => {
255308
const a = jasmine.createSpy()
256309
const b = jasmine.createSpy()

0 commit comments

Comments
 (0)