test(client): questions store

test/vue
sundowndev 2019-10-29 23:27:35 +01:00
parent e215a427d7
commit 2b67bef6da
1 changed files with 57 additions and 1 deletions

View File

@ -1,10 +1,13 @@
import { MutationTree, GetterTree } from 'vuex';
import { MutationTree, GetterTree, ActionTree } from 'vuex';
import questions, {
IStoreQuestions,
} from '../../../src/store/modules/questions';
import axios from 'axios';
import config from '@/config';
const getters = questions.getters as GetterTree<IStoreQuestions, any>;
const mutations = questions.mutations as MutationTree<IStoreQuestions>;
const actions = questions.actions as any;
let state: IStoreQuestions;
@ -160,4 +163,57 @@ describe('Store - Questions', () => {
});
});
});
describe('Actions', () => {
describe('#increaseIndex', () => {
it('should commit increaseIndex', async () => {
const commitMock = jest.fn();
await actions.increaseIndex({ commit: commitMock });
expect(commitMock).toBeCalledTimes(1);
expect(commitMock).toHaveBeenCalledWith('increaseIndex');
});
});
describe('#increaseScore', () => {
it('should commit increaseScore', async () => {
const commitMock = jest.fn();
await actions.increaseScore({ commit: commitMock });
expect(commitMock).toBeCalledTimes(1);
expect(commitMock).toHaveBeenCalledWith('increaseScore');
});
});
describe('#fetchQuestions', () => {
it('should fetch questions from API', async () => {
const payload = [{ id: '2', name: 'test' }];
const axiosMock = jest.spyOn(axios, 'get').mockResolvedValue({
data: { questions: payload },
} as any);
const commitMock = jest.fn();
await actions.fetchQuestions({ commit: commitMock });
expect(axiosMock).toBeCalledTimes(1);
expect(axiosMock).toHaveBeenCalledWith(`${config.apiUrl}/questions`);
expect(commitMock).toBeCalledTimes(1);
expect(commitMock).toHaveBeenCalledWith('setQuestions', payload);
});
});
describe('#resetState', () => {
it('should commit resetState', async () => {
const commitMock = jest.fn();
await actions.resetState({ commit: commitMock });
expect(commitMock).toBeCalledTimes(1);
expect(commitMock).toHaveBeenCalledWith('resetState');
});
});
});
});