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);
}
};
Файл теста:
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();
});
});
});
});
Геттеры и state работает.