unit testing functionality for mount options

This commit is contained in:
Max 2021-11-12 13:44:58 -05:00
parent 95de6007de
commit 968ade9afa
2 changed files with 26 additions and 6 deletions

View file

@ -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}
}
})

View file

@ -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) => {