unit testing
This commit is contained in:
parent
918addb3cb
commit
75f7c4abbc
3 changed files with 22 additions and 11 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ export default {
|
||||||
years: Array,
|
years: Array,
|
||||||
modelValue: String
|
modelValue: String
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
},
|
|
||||||
components: {
|
components: {
|
||||||
radioQuestion,
|
radioQuestion,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue