Last active
October 9, 2020 19:56
-
-
Save EricRohlfs/fe55b8d157a3fcd4c1cfb2806741ab33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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