github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/web/src/store/modules/user/__tests__/user.spec.ts (about) 1 import { mock } from 'jest-mock-extended'; 2 import { ActionContext } from 'vuex'; 3 import { UserState, Mutations } from '..'; 4 import { fetchSCM } from '../actions'; 5 import { RootState } from '@/store'; 6 import axios, { AxiosResponse } from 'axios'; 7 8 describe('store.module.user', () => { 9 let context: ActionContext<UserState, RootState>; 10 beforeEach(() => { 11 context = mock<ActionContext<UserState, RootState>>(); 12 context.rootState.base = ''; 13 }); 14 15 it('commit user scm after fetch', async () => { 16 const state = { 17 gitea: true, 18 github: false 19 }; 20 const mockGet = jest.spyOn(axios, 'get'); 21 mockGet.mockResolvedValueOnce({ 22 status: 200, 23 data: state 24 } as AxiosResponse); 25 await fetchSCM(context); 26 expect(mockGet).toHaveBeenCalled(); 27 expect(context.commit).toHaveBeenCalledWith(Mutations.START_USER_LOADING); 28 expect(context.commit).toHaveBeenCalledWith(Mutations.UPDATE_USER_SCM, state); 29 expect(context.commit).toHaveBeenLastCalledWith(Mutations.STOP_USER_LOADING); 30 }); 31 });