V
V
Vladimir Golub2020-01-28 10:31:33
Vue.js
Vladimir Golub, 2020-01-28 10:31:33

vuex testing why can't copy action and mutations?

export const state  = () => ({
  langs: []
});

export const mutations = {
  setLangs: (state, langs) => {
    state.langs = langs;
  }
};

export const getters = {
  langs: state => state.langs
};

export const actions = {
  getLangs: async ({commit}) => {
    const langs = await this.$axios.$get('/langs');
    //const {data} = await this.$axios.get('/langs');

    console.log(langs);
    //console.log(data.langs)

    commit('setLangs', langs);
    //commit('setLangs', data.langs);
  }
};


Test file
import {actions, getters, mutations, state} from './../store/index';
import { createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';

describe(`store`, () => {
  describe(`actions`, () => {
    describe(action = 'getLangs', () => {
      it(`returns an empty array if axios returns an empty array`, async (done) => {
        const localVue = createLocalVue();
        localVue.use(Vuex);

        const store = new Vuex.Store({
          state: {
            count: 0
          },
          getters,
          mutations,
        });

        console.log({'actions mutations' : store.mutations}); // undefine
        console.log({'actions store': store.actions}) // undefine


        done();
      });
    });
  });
});


Getters and state works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Golub, 2020-01-28
@RazerVG

console.log({'actions mutations' : store._mutations.setLangs});
        console.log({'actions store': store._actions.getLangs});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question