From b4be27bb40b20f9220eef48cae9fa301638a6e23 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Sat, 7 Dec 2019 17:51:17 +0100 Subject: [PATCH] test(client): score screen component --- .../tests/unit/components/ScoreScreen.spec.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 client/tests/unit/components/ScoreScreen.spec.ts diff --git a/client/tests/unit/components/ScoreScreen.spec.ts b/client/tests/unit/components/ScoreScreen.spec.ts new file mode 100644 index 0000000..7fd92f2 --- /dev/null +++ b/client/tests/unit/components/ScoreScreen.spec.ts @@ -0,0 +1,45 @@ +import { createLocalVue, shallowMount } from '@vue/test-utils'; +import Vuex from 'vuex'; +import ScoreScreen from '../../../src/components/ScoreScreen.vue'; + +const localVue = createLocalVue(); + +localVue.use(Vuex); + +const $store = new Vuex.Store({ + modules: { + questions: { + namespaced: true, + state: { + index: 0, + score: 0, + questions: [], + }, + }, + }, +}); + +const resetMock = jest.fn(); + +const wrapper = shallowMount(ScoreScreen, { + mocks: { $store }, + propsData: { + score: 2, + count: 5, + reset: resetMock, + }, +}); + +describe('Component - ScoreScreen', () => { + it('should display message based on score', () => { + expect(wrapper.find('h3').text()).toBe( + 'Bon bah c\'est pas tip top tout ça.', + ); + }); + + it('should call reset state function', () => { + wrapper.find('button.replay-btn').trigger('click'); + + expect(resetMock).toBeCalledTimes(1); + }); +});