April 2017
Intermediate to advanced
454 pages
12h 51m
English
To be able to test your mutations, you have to make them available for your test files. To do this, you have to extract the mutation object from your store. Consider something like this:
import Vuex from 'vuex'import Vue from 'vue'Vue.use(Vuex)const store = new Vuex.Store({ ... mutations: { ... MARK_ITEM_AS_DONE (state, itemId) { state.todo.filter(item => { return item.id === itemId }).forEach(item => { item.done = true }) state.archived.filter(item => { return item.id === itemId }).forEach(item => { item.done = true }) } }}) export default store
You have to extract it to something similar to this:
export const mutations = { ... }const store = new Vuex.Store({ ... })export default store
This way, you can import the mutations ...
Read now
Unlock full access