|
@@ -39,6 +39,31 @@ describe('Helpers', () => {
|
|
|
expect(vm.a).toBe(4)
|
|
|
})
|
|
|
|
|
|
+ it('mapState (with namespace)', () => {
|
|
|
+ const store = new Vuex.Store({
|
|
|
+ modules: {
|
|
|
+ foo: {
|
|
|
+ namespaced: true,
|
|
|
+ state: { a: 1 },
|
|
|
+ getters: {
|
|
|
+ b: state => state.a + 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const vm = new Vue({
|
|
|
+ store,
|
|
|
+ computed: mapState('foo', {
|
|
|
+ a: (state, getters) => {
|
|
|
+ return state.a + getters.b
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ expect(vm.a).toBe(3)
|
|
|
+ store.state.foo.a++
|
|
|
+ expect(vm.a).toBe(5)
|
|
|
+ })
|
|
|
+
|
|
|
it('mapMutations (array)', () => {
|
|
|
const store = new Vuex.Store({
|
|
|
state: { count: 0 },
|
|
@@ -78,6 +103,32 @@ describe('Helpers', () => {
|
|
|
expect(store.state.count).toBe(0)
|
|
|
})
|
|
|
|
|
|
+ it('mapMutations (with namespace)', () => {
|
|
|
+ const store = new Vuex.Store({
|
|
|
+ modules: {
|
|
|
+ foo: {
|
|
|
+ namespaced: true,
|
|
|
+ state: { count: 0 },
|
|
|
+ mutations: {
|
|
|
+ inc: state => state.count++,
|
|
|
+ dec: state => state.count--
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const vm = new Vue({
|
|
|
+ store,
|
|
|
+ methods: mapMutations('foo', {
|
|
|
+ plus: 'inc',
|
|
|
+ minus: 'dec'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ vm.plus()
|
|
|
+ expect(store.state.foo.count).toBe(1)
|
|
|
+ vm.minus()
|
|
|
+ expect(store.state.foo.count).toBe(0)
|
|
|
+ })
|
|
|
+
|
|
|
it('mapGetters (array)', () => {
|
|
|
const store = new Vuex.Store({
|
|
|
state: { count: 0 },
|
|
@@ -135,6 +186,41 @@ describe('Helpers', () => {
|
|
|
expect(vm.b).toBe(true)
|
|
|
})
|
|
|
|
|
|
+ it('mapGetters (with namespace)', () => {
|
|
|
+ const store = new Vuex.Store({
|
|
|
+ modules: {
|
|
|
+ foo: {
|
|
|
+ namespaced: true,
|
|
|
+ state: { count: 0 },
|
|
|
+ mutations: {
|
|
|
+ inc: state => state.count++,
|
|
|
+ dec: state => state.count--
|
|
|
+ },
|
|
|
+ getters: {
|
|
|
+ hasAny: ({ count }) => count > 0,
|
|
|
+ negative: ({ count }) => count < 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const vm = new Vue({
|
|
|
+ store,
|
|
|
+ computed: mapGetters('foo', {
|
|
|
+ a: 'hasAny',
|
|
|
+ b: 'negative'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ expect(vm.a).toBe(false)
|
|
|
+ expect(vm.b).toBe(false)
|
|
|
+ store.commit('foo/inc')
|
|
|
+ expect(vm.a).toBe(true)
|
|
|
+ expect(vm.b).toBe(false)
|
|
|
+ store.commit('foo/dec')
|
|
|
+ store.commit('foo/dec')
|
|
|
+ expect(vm.a).toBe(false)
|
|
|
+ expect(vm.b).toBe(true)
|
|
|
+ })
|
|
|
+
|
|
|
it('mapActions (array)', () => {
|
|
|
const a = jasmine.createSpy()
|
|
|
const b = jasmine.createSpy()
|
|
@@ -177,4 +263,32 @@ describe('Helpers', () => {
|
|
|
vm.bar()
|
|
|
expect(b).toHaveBeenCalled()
|
|
|
})
|
|
|
+
|
|
|
+ it('mapActions (with namespace)', () => {
|
|
|
+ const a = jasmine.createSpy()
|
|
|
+ const b = jasmine.createSpy()
|
|
|
+ const store = new Vuex.Store({
|
|
|
+ modules: {
|
|
|
+ foo: {
|
|
|
+ namespaced: true,
|
|
|
+ actions: {
|
|
|
+ a,
|
|
|
+ b
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const vm = new Vue({
|
|
|
+ store,
|
|
|
+ methods: mapActions('foo/', {
|
|
|
+ foo: 'a',
|
|
|
+ bar: 'b'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ vm.foo()
|
|
|
+ expect(a).toHaveBeenCalled()
|
|
|
+ expect(b).not.toHaveBeenCalled()
|
|
|
+ vm.bar()
|
|
|
+ expect(b).toHaveBeenCalled()
|
|
|
+ })
|
|
|
})
|