Large Application Patterns with Vuex Chapter 18
}).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 in your test files with the following line:
import { mutations } from '@/store'
The test for requirement number 1 can be written as follows:
describe('mutations', () => {
it(`MARK_ITEM_AS_DONE mutation must change the
done field from false to true for a todo`, () => {
const state = {
todo: [
{ id: 43, text: 'Buy iPhone', done: false }
],
archived: [
{ id: 40, text: 'Buy cat', done: false }
]
}
mutations.MARK_ITEM_AS_DONE(state, 43)
expect(state.todo[0].done).to.be.true
})
})