Skip to content

Instantly share code, notes, and snippets.

@EricRohlfs
Last active October 9, 2020 19:56
Show Gist options
  • Save EricRohlfs/fe55b8d157a3fcd4c1cfb2806741ab33 to your computer and use it in GitHub Desktop.
Save EricRohlfs/fe55b8d157a3fcd4c1cfb2806741ab33 to your computer and use it in GitHub Desktop.
const mockCommit = function (mutations, state) {
return function (type, payload) {
mutations[type](state, payload)
}
}
// how to do async unit test for vuex without creating a full store.
describe('inFlight vuex', () => {
let state
let mutations
let commit
var axios = {
get: () => {}
}
const actions = {
loadVisitors ({ state, commit }) {
tryFlight(state, commit, actions.loadVisitors.name)
axios.get('')
endFlight(commit, actions.loadVisitors.name)
}
}
beforeEach(() => {
state = {}
initInFlight(state, actions)
mutations = {
setInFlightStatus
}
commit = mockCommit(mutations, state)
})
it('', async () => {
jest.mock('axios')
axios.get = jest.fn((url) => {
expect(state.inFlight.loadVisitors).to.be.equal(true)
return {}
})
await actions.loadVisitors({ commit, state })
expect(state.inFlight.loadVisitors).to.be.equal(false)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment