chore: adjust path of test utils (#4997)
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import Vue from 'vue';
|
||||
import '../docs/site/mobile/demo-common';
|
||||
import Locale from '../src/locale';
|
||||
import { mount, later } from './utils';
|
||||
|
||||
const empty = {
|
||||
render(h) {
|
||||
return h('div', [this.$slots.default]);
|
||||
},
|
||||
inheritAttrs: false
|
||||
};
|
||||
|
||||
Vue.component('demo-block', empty);
|
||||
Vue.component('demo-section', empty);
|
||||
|
||||
export default function (Demo: any, option: any = {}) {
|
||||
test('renders demo correctly', async () => {
|
||||
if (option.hookBeforeTest) {
|
||||
option.hookBeforeTest();
|
||||
}
|
||||
|
||||
if (Demo.i18n) {
|
||||
Locale.add(Demo.i18n);
|
||||
}
|
||||
|
||||
const wrapper = mount(Demo);
|
||||
|
||||
await later();
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
||||
if (option.hookAfterTest) {
|
||||
option.hookAfterTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import Vue, { CreateElement } from 'vue';
|
||||
import '../docs/site/mobile/demo-common';
|
||||
import Locale from '../src/locale';
|
||||
import { mount, later } from '.';
|
||||
|
||||
const Empty = {
|
||||
render(h: CreateElement): ReturnType<CreateElement> {
|
||||
return h('div', [(this as any).$slots.default]);
|
||||
},
|
||||
inheritAttrs: false
|
||||
};
|
||||
|
||||
Vue.component('demo-block', Empty);
|
||||
Vue.component('demo-section', Empty);
|
||||
|
||||
export function snapshotDemo(Demo: any, option: any = {}) {
|
||||
test('renders demo correctly', async () => {
|
||||
if (option.beforeTest) {
|
||||
option.beforeTest();
|
||||
}
|
||||
|
||||
if (Demo.i18n) {
|
||||
Locale.add(Demo.i18n);
|
||||
}
|
||||
|
||||
const wrapper = mount(Demo);
|
||||
|
||||
await later();
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
||||
if (option.afterTest) {
|
||||
option.afterTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -32,12 +32,14 @@ function mockHTMLElementOffset() {
|
||||
|
||||
mockHTMLElementOffset();
|
||||
|
||||
export function mockGetBoundingClientRect(rect: ClientRect | DOMRect): Function {
|
||||
export function mockGetBoundingClientRect(
|
||||
rect: ClientRect | DOMRect
|
||||
): Function {
|
||||
const originMethod = Element.prototype.getBoundingClientRect;
|
||||
|
||||
Element.prototype.getBoundingClientRect = <any>jest.fn(() => rect);
|
||||
|
||||
return function () {
|
||||
return function() {
|
||||
Element.prototype.getBoundingClientRect = originMethod;
|
||||
};
|
||||
}
|
||||
@@ -1,17 +1,26 @@
|
||||
import Vue from 'vue';
|
||||
import './transition';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { mount, TransitionStub } from '@vue/test-utils';
|
||||
import { trigger, triggerDrag } from './event';
|
||||
import { mockScrollTop, mockGetBoundingClientRect } from './dom';
|
||||
|
||||
// prevent vue warning log
|
||||
Vue.config.silent = true;
|
||||
|
||||
// stub transition
|
||||
Vue.component('transition', TransitionStub as any);
|
||||
|
||||
// promisify setTimeout
|
||||
function later(delay: number = 0): Promise<void> {
|
||||
export function later(delay: number = 0): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
}
|
||||
|
||||
export { mount, later, trigger, triggerDrag, mockScrollTop, mockGetBoundingClientRect };
|
||||
export {
|
||||
mount,
|
||||
trigger,
|
||||
triggerDrag,
|
||||
mockScrollTop,
|
||||
mockGetBoundingClientRect
|
||||
};
|
||||
Reference in New Issue
Block a user