unit testing

This commit is contained in:
Max 2021-12-06 16:55:52 -05:00
parent 918addb3cb
commit 75f7c4abbc
3 changed files with 22 additions and 11 deletions

View file

@ -1,16 +1,30 @@
import { shallowMount } from "@vue/test-utils"; import { shallowMount } from "@vue/test-utils";
import radioQuestion from "@/common-components/radio-question/radio-question"; import radioQuestion from "@/common-components/radio-question/radio-question";
import { getMountOptions } from "@/helpers/unit-test-helper";
describe("radioQuestion.vue", () => { 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.", () => { 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 () => {
// Act // Arrange
const wrapper = shallowMount(radioQuestion, { const chooseAnswer = jest.fn();
propsData: { chooseAnswer.mockImplementation((answer) => {
questionText: "Question Text", mockData.answer = answer;
answers: ["2023", "2022", "2021"],
modelValue: '2020'
},
}); });
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 // Assert
expect(wrapper.find(".needed_car_info-text").text()).toEqual( expect(wrapper.find(".needed_car_info-text").text()).toEqual(

View file

@ -33,7 +33,6 @@ export default {
answers: Array, answers: Array,
modelValue: String modelValue: String
}, },
emits: ['update:modelValue'],
methods: { methods: {
chooseAnswer(answer) { chooseAnswer(answer) {
this.$emit('update:modelValue', answer); this.$emit('update:modelValue', answer);

View file

@ -21,8 +21,6 @@ export default {
years: Array, years: Array,
modelValue: String modelValue: String
}, },
created() {
},
components: { components: {
radioQuestion, radioQuestion,
}, },