ant-design-vue/tests/shared/demoTest.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-01-12 11:33:27 +08:00
import glob from 'glob';
import { mount } from '@vue/test-utils';
import MockDate from 'mockdate';
import moment from 'moment';
import Vue from 'vue';
import antd from 'ant-design-vue';
Vue.use(antd);
2018-05-13 23:11:51 +08:00
2019-01-12 11:33:27 +08:00
export default function demoTest(component, options = {}) {
const suffix = options.suffix || 'md';
const files = glob.sync(`./components/${component}/demo/*.${suffix}`);
2018-05-13 23:11:51 +08:00
2019-01-12 11:33:27 +08:00
files.forEach(file => {
let testMethod = options.skip === true ? test.skip : test;
2018-05-13 23:11:51 +08:00
if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) {
2019-01-12 11:33:27 +08:00
testMethod = test.skip;
2018-05-13 23:11:51 +08:00
}
2019-01-12 11:33:27 +08:00
testMethod(`renders ${file} correctly`, done => {
MockDate.set(moment('2016-11-22'));
const demo = require(`../.${file}`).default || require(`../.${file}`); // eslint-disable-line global-require, import/no-dynamic-require
const wrapper = mount(demo, { sync: false });
2018-05-18 22:04:10 +08:00
Vue.nextTick(() => {
2019-01-12 11:33:27 +08:00
expect(wrapper.html()).toMatchSnapshot();
MockDate.reset();
wrapper.destroy();
done();
});
});
});
2018-05-13 23:11:51 +08:00
}