2023-04-23 21:23:45 +05:30
|
|
|
import { createWrapper } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
|
|
|
import { initSimpleApp } from '~/helpers/init_simple_app_helper';
|
|
|
|
|
|
|
|
const MockComponent = Vue.component('MockComponent', {
|
|
|
|
props: {
|
|
|
|
someKey: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
count: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render: (createElement) => createElement('span'),
|
|
|
|
});
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findMock = () => wrapper.findComponent(MockComponent);
|
|
|
|
|
|
|
|
const didCreateApp = () => wrapper !== undefined;
|
|
|
|
|
|
|
|
const initMock = (html, props = {}) => {
|
|
|
|
setHTMLFixture(html);
|
|
|
|
|
|
|
|
const app = initSimpleApp('#mount-here', MockComponent, { props });
|
|
|
|
|
|
|
|
wrapper = app ? createWrapper(app) : undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('helpers/init_simple_app_helper/initSimpleApp', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('mounts the component if the selector exists', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
initMock('<div id="mount-here"></div>');
|
|
|
|
|
|
|
|
expect(findMock().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('does not mount the component if selector does not exist', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
initMock('<div id="do-not-mount-here"></div>');
|
|
|
|
|
|
|
|
expect(didCreateApp()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('passes the prop to the component if the prop exists', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
initMock(`<div id="mount-here" data-view-model={"someKey":"thing","count":123}></div>`);
|
|
|
|
|
|
|
|
expect(findMock().props()).toEqual({
|
|
|
|
someKey: 'thing',
|
|
|
|
count: 123,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|