From 968ade9afaf97bc5df68959c760cf9e1975de9a2 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 12 Nov 2021 13:44:58 -0500 Subject: [PATCH] unit testing functionality for mount options --- src/layouts/selectYear/selectYear.spec.js | 30 +++++++++++++++++++---- src/layouts/selectYear/selectYear.vue | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/layouts/selectYear/selectYear.spec.js b/src/layouts/selectYear/selectYear.spec.js index f92c5cfc3..760063ff9 100644 --- a/src/layouts/selectYear/selectYear.spec.js +++ b/src/layouts/selectYear/selectYear.spec.js @@ -1,11 +1,12 @@ -import { mount } from '@vue/test-utils'; -import selectYear from './selectYear'; +import { shallowMount } from '@vue/test-utils'; +import selectYear from './selectYear.vue'; describe('selectYear.vue', () => { - it("Should render the 'pageHeader.Text' data value 'text' prop value for the Header component, 'radioQuestion.Question' data value as 'questionText' prop value for the 'radioQuestion' component and 'years' values for 'answers' prop values for the 'radioQuestion' component.", async () => { + test("Should render the 'pageHeader.Text' data value 'text' prop value for the Header component, 'radioQuestion.Question' data value as 'questionText' prop value for the 'radioQuestion' component and 'years' values for 'answers' prop values for the 'radioQuestion' component.", async () => { // Act - const wrapper = mount(selectYear); + const mountOptions = getMountOptions({}); + const wrapper = shallowMount(selectYear, mountOptions); await wrapper.setData({ years: ['2023', '2022', '2021'], @@ -24,5 +25,24 @@ describe('selectYear.vue', () => { const radioQuestion = wrapper.findComponent('.radioQuestion'); expect(radioQuestion.attributes('answers')).toEqual('2023,2022,2021'); expect(radioQuestion.attributes('questiontext')).toEqual('Test question'); - }) + }); + + function getMountOptions({data}){ + let response = data; + const mocks = {}; + mocks.$store = { + getters: { + + } + } + mocks.dispatchNonBlockingStoreAction = jest.fn(); + mocks.dispatchNonBlockingStoreAction.mockImplementation((actionName) => { + return Promise.resolve(response); + }); + const global = { + mocks: mocks + } + return {global} + + } }) \ No newline at end of file diff --git a/src/layouts/selectYear/selectYear.vue b/src/layouts/selectYear/selectYear.vue index 0c9ba5ea2..98c0a240f 100644 --- a/src/layouts/selectYear/selectYear.vue +++ b/src/layouts/selectYear/selectYear.vue @@ -39,7 +39,7 @@ export default { .then( (response) => { this.years = response.data; }); - + // Mocking Sitefinity data this.dispatchNonBlockingStoreAction("getMockPageData", {relativeUrl: 'https://mockey.qa.sagaws.net/service/content/selectYear'}) .then( (response) => {