I am currently working on a store.js file
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export const mutations = {
increment: state => state.count++,
Changeloading(state, status) { state.loading = status },
ChangeUserGroup(state, newGroup) { state.userGroup = newGroup; },
ChangeOriginalRole(state, newRole) { state.originalRole = newRole; }
}
export default new Vuex.Store({
state: {
count: 0,
loading: false, //header, TeamLead, TeamMember
listUserGroup: [],
userRole: "",
originalRole: "",
userGroup: {}
},
mutations,
...
})
In my testing file store.spec.js
import { expect } from 'chai'
import mutations from '@/store'
// destructure assign `mutations`
const { increment } = mutations
describe('mutations', () => {
it('INCREMENT', () => {
// mock state
const state = { count: 0 }
// apply mutation
increment(state)
// assert result
expect(state.count).to.equal(1)
})
})
Upon running the tests, I encountered the following error message:
mutations 1) INCREMENT
0 passing (75ms) 1 failing
1) mutations INCREMENT: TypeError: increment is not a function
at Context.increment (dist\webpack:\tests\unit\store.spec.js:13:5)
UPDATE (4/16/2019)
To troubleshoot the issue, I read that all components in my store.js should be "exported" like so:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const mutations = {...};
export const state = {...};
export const actions = {...};
export const getters = {...};
export default new Vuex.Store({
state,
mutations,
actions,
getters
});
Even after making these changes, the testing still fails with the same error message.
0 passing (61ms) 1 failing
1) mutations increment: TypeError: increment is not a function at Context.increment (dist\webpack:\tests\unit\store.spec.js:12:5)