test(client): home view unit test

pull/12/head
sundowndev 2019-12-07 16:56:50 +01:00
parent e402799222
commit 9e6d1142d2
2 changed files with 13 additions and 22 deletions

View File

@ -5,21 +5,16 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from "vue";
import { mapState, mapGetters, mapMutations } from 'vuex'; import { mapState, mapGetters, mapMutations } from "vuex";
import Quiz from '../components/Quiz.vue'; import Quiz from "../components/Quiz.vue";
export default Vue.extend({ export default Vue.extend({
name: 'home', name: "home",
data() {
return {};
},
computed: {},
methods: {},
components: { Quiz }, components: { Quiz },
async created() { async created() {
await this.$store.dispatch('questions/fetchQuestions'); await this.$store.dispatch("questions/fetchQuestions");
await this.$store.dispatch('schools/fetchSchools'); await this.$store.dispatch("schools/fetchSchools");
}, }
}); });
</script> </script>

View File

@ -4,7 +4,7 @@ import Home from '../../../src/views/Home.vue';
import axios from 'axios'; import axios from 'axios';
import config from '@/config'; import config from '@/config';
import questions from '@/store/modules/questions'; import questions from '@/store/modules/questions';
import schools from '@/store/modules/questions'; import schools from '@/store/modules/schools';
const localVue = createLocalVue(); const localVue = createLocalVue();
@ -18,17 +18,13 @@ const $store = new Vuex.Store({
}); });
const axiosMock = jest const axiosMock = jest
.spyOn(axios, 'get') .spyOn(axios, 'get')
.mockResolvedValue({ data: { questions: [] } } as any); .mockResolvedValueOnce({ data: { questions: [] } } as any)
const wrapper = shallowMount(Home, { mocks: { $store } }); .mockResolvedValueOnce({ data: { schools: [] } } as any);
describe.skip('Views - Home', () => { shallowMount(Home, { mocks: { $store } });
it('should ', () => {
const storeDispatchMock = spyOn($store, 'dispatch');
// wrapper.find('.todoList__removeDone').trigger('click'); describe('Views - Home', () => {
// expect(storeDispatchMock).toBeCalledTimes(2); it('should fetch questions and shools', () => {
// expect(storeDispatchMock).toHaveBeenNthCalledWith(1, 'fetchQuestions');
// expect(storeDispatchMock).toHaveBeenNthCalledWith(2, 'fetchSchools');
expect(axiosMock).toBeCalledTimes(2); expect(axiosMock).toBeCalledTimes(2);
expect(axiosMock).toHaveBeenNthCalledWith(1, `${config.apiUrl}/questions`); expect(axiosMock).toHaveBeenNthCalledWith(1, `${config.apiUrl}/questions`);
expect(axiosMock).toHaveBeenNthCalledWith(2, `${config.apiUrl}/schools`); expect(axiosMock).toHaveBeenNthCalledWith(2, `${config.apiUrl}/schools`);