Adding unit tests

This commit is contained in:
Max 2021-11-10 09:41:10 -05:00
parent 984879c717
commit e4a7f30c77
4 changed files with 49 additions and 38 deletions

View file

@ -1,18 +1,23 @@
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import radioQuestion from './radioQuestion'; import radioQuestion from './radioQuestion';
test('radioQuestion', () => { describe('radioQuestion.vue', () => {
// render the component it("Should render the 'questionText' prop value as a span value for the radio question.", () => {
const wrapper = shallowMount(radioQuestion, { // Act
propsData: { const wrapper = shallowMount(radioQuestion, {
questionText: 'testString', propsData: {
chooseAnswer: function(){ console.log('test') } questionText: 'Question Text',
} answers: ['Value_1', 'Value_2', 'Value_3'],
}); chooseAnswer: function(){ console.log('test') }
}
});
// test if questionText is a string const radioButtons = wrapper.findAllComponents('[data-test="radio"]')
expect(typeof wrapper.props().questionText).toBe('string');
// test if chooseAnswer is a function // Assert
expect(typeof wrapper.props().chooseAnswer).toBe('function'); expect(wrapper.find('.needed_car_info-text').text()).toEqual('Question Text');
}); expect(radioButtons[0].attributes('text')).toEqual('Value_1');
expect(radioButtons[2].attributes('text')).toEqual('Value_3');
expect(typeof wrapper.props().chooseAnswer).toBe('function');
})
})

View file

@ -5,7 +5,7 @@
</div> </div>
<div class="car_list overflow-scroll position-absolute"> <div class="car_list overflow-scroll position-absolute">
<div v-for="answer in answers" :key="answer" class="mb-2"> <div v-for="answer in answers" :key="answer" class="mb-2">
<radio :text="answer" :value="answer" @click="chooseAnswer(answer)" /> <radio :text="answer" :value="answer" @click="chooseAnswer(answer)" data-test="radio" />
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,15 +1,16 @@
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Header from './header'; import Header from './header';
test('Header', () => { describe('Header.vue', () => {
// render the component it("Should render the 'text' prop value as a span value for the header span text value.", () => {
const wrapper = shallowMount(Header, { // Act
propsData: { const wrapper = shallowMount(Header, {
text: 'testString' propsData: {
} text: 'Header Content'
}); }
});
// test if text is a string
expect(typeof wrapper.props().text).toBe('string');
// Assert
expect(wrapper.find('span').text()).toContain("Header Content");
})
}); });

View file

@ -1,18 +1,23 @@
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import radio from './radio'; import radio from './radio';
test('radioQuestion', () => { describe('radio.vue', () => {
// render the component it("Should render the 'text' prop value as a span value for the radio button label and add the 'value' prop value as the radio button value and id.", () => {
const wrapper = shallowMount(radio, { // Act
propsData: { const wrapper = shallowMount(radio, {
value: 'testString', propsData: {
text: 'testString2' value: 'radio_button_value',
} text: 'Radio Button Text'
}); }
});
// test if value is a string // Assert
expect(typeof wrapper.props().value).toBe('string'); expect(wrapper.find('span').text()).toEqual('Radio Button Text');
expect(wrapper.find('input').attributes()).toEqual({
// test if text is a string class: 'position-absolute opacity-0',
expect(typeof wrapper.props().text).toBe('string'); id: 'radio_button_value',
}); type: 'radio',
value: 'radio_button_value'
});
})
})