From 75f7c4abbc33eb33eb65ef98556b6ac7aeb1f6cd Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 6 Dec 2021 16:55:52 -0500 Subject: [PATCH] unit testing --- .../radio-question/radio-question.spec.js | 30 ++++++++++++++----- .../radio-question/radio-question.vue | 1 - .../year-question/year-question.vue | 2 -- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/common-components/radio-question/radio-question.spec.js b/src/common-components/radio-question/radio-question.spec.js index e1d8f8dfd..671926086 100644 --- a/src/common-components/radio-question/radio-question.spec.js +++ b/src/common-components/radio-question/radio-question.spec.js @@ -1,16 +1,30 @@ import { shallowMount } from "@vue/test-utils"; import radioQuestion from "@/common-components/radio-question/radio-question"; +import { getMountOptions } from "@/helpers/unit-test-helper"; describe("radioQuestion.vue", () => { - it("Should render the 'questionText' prop value as a span value for the radio question and the 'answer' values should render as text values for radio components.", () => { - // Act - const wrapper = shallowMount(radioQuestion, { - propsData: { - questionText: "Question Text", - answers: ["2023", "2022", "2021"], - modelValue: '2020' - }, + it("Should render the 'questionText' prop value as a span value for the radio question and the 'answer' values should render as text values for radio components.", async () => { + // Arrange + const chooseAnswer = jest.fn(); + chooseAnswer.mockImplementation((answer) => { + mockData.answer = answer; }); + const mockData = { + chooseAnswer: chooseAnswer, + answer: '' + } + + const mountOptions = getMountOptions(mockData); + + // Act + const wrapper = shallowMount(radioQuestion, mountOptions) + await wrapper.setProps({ + questionText: "Question Text", + answers: ["2023", "2022", "2021"], + modelValue: "2020" + }); + //wrapper.vm.chooseAnswer("2021"); + console.log(mockData.answer); // Assert expect(wrapper.find(".needed_car_info-text").text()).toEqual( diff --git a/src/common-components/radio-question/radio-question.vue b/src/common-components/radio-question/radio-question.vue index c0460ad58..828c66b29 100644 --- a/src/common-components/radio-question/radio-question.vue +++ b/src/common-components/radio-question/radio-question.vue @@ -33,7 +33,6 @@ export default { answers: Array, modelValue: String }, - emits: ['update:modelValue'], methods: { chooseAnswer(answer) { this.$emit('update:modelValue', answer); diff --git a/src/layouts/vehicle-year/year-question/year-question.vue b/src/layouts/vehicle-year/year-question/year-question.vue index 07c70a1c7..4c5bb8d30 100644 --- a/src/layouts/vehicle-year/year-question/year-question.vue +++ b/src/layouts/vehicle-year/year-question/year-question.vue @@ -21,8 +21,6 @@ export default { years: Array, modelValue: String }, - created() { - }, components: { radioQuestion, },