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';
|
2020-08-12 20:26:09 +08:00
|
|
|
import { nextTick } from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
import antd from 'ant-design-vue';
|
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';
|
2020-03-15 13:12:47 +08:00
|
|
|
const files = glob.sync(`./antdv-demo/docs/${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'));
|
2020-03-07 19:45:13 +08:00
|
|
|
const demo = require(`../.${file}`).default || require(`../.${file}`);
|
2020-07-03 18:13:38 +08:00
|
|
|
document.body.innerHTML = '';
|
2020-08-12 20:26:09 +08:00
|
|
|
const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body });
|
2020-07-24 18:46:45 +08:00
|
|
|
nextTick(() => {
|
2020-03-07 19:45:13 +08:00
|
|
|
// should get dom from element
|
|
|
|
// snap files copy from antd does not need to change
|
|
|
|
// or just change a little
|
|
|
|
const dom = options.getDomFromElement ? wrapper.element : wrapper.html();
|
|
|
|
expect(dom).toMatchSnapshot();
|
2019-01-12 11:33:27 +08:00
|
|
|
MockDate.reset();
|
2020-08-12 20:26:09 +08:00
|
|
|
// wrapper.unmount();
|
2020-07-03 18:13:38 +08:00
|
|
|
document.body.innerHTML = '';
|
2019-01-12 11:33:27 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-13 23:11:51 +08:00
|
|
|
}
|