test: fix demo snapshot

This commit is contained in:
chenjiahan
2020-08-22 10:59:22 +08:00
parent f0482c7eec
commit 6016a4acf1
4 changed files with 143 additions and 142 deletions
+16 -10
View File
@@ -1,18 +1,15 @@
import Vue, { CreateElement } from 'vue';
import '../docs/site/mobile';
import { h } from 'Vue';
import Locale from '../src/locale';
import { mount, later } from '.';
import { DemoLocaleMixin } from '../docs/site/demo-locale';
const Empty = {
render(h: CreateElement): ReturnType<CreateElement> {
return h('div', [(this as any).$slots.default]);
const EmptyComponent = {
render() {
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) {
@@ -23,11 +20,20 @@ export function snapshotDemo(Demo: any, option: any = {}) {
Locale.add(Demo.i18n);
}
const wrapper = mount(Demo);
const wrapper = mount(Demo, {
global: {
mixins: [DemoLocaleMixin],
components: {
'demo-block': EmptyComponent,
'demo-section': EmptyComponent,
},
plugins: [(window as any).vant],
},
});
await later();
expect(wrapper).toMatchSnapshot();
expect(wrapper.html()).toMatchSnapshot();
if (option.afterTest) {
option.afterTest();
+2 -11
View File
@@ -1,14 +1,5 @@
import Vue from 'vue';
import { mount, TransitionStub } from '@vue/test-utils';
// prevent vue warning log
Vue.config.silent = true;
// stub transition
Vue.component('transition', TransitionStub as any);
// promisify setTimeout
export function later(delay: number = 0): Promise<void> {
export function later(delay = 0): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, delay);
});
@@ -16,4 +7,4 @@ export function later(delay: number = 0): Promise<void> {
export * from './dom';
export * from './event';
export { mount };
export { mount } from '@vue/test-utils';