2019-01-12 03:33:27 +00:00
|
|
|
import glob from 'glob';
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import MockDate from 'mockdate';
|
|
|
|
import moment from 'moment';
|
2020-08-12 12:26:09 +00:00
|
|
|
import { nextTick } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import antd from 'ant-design-vue';
|
2018-05-13 15:11:51 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default function demoTest(component, options = {}) {
|
|
|
|
const suffix = options.suffix || 'md';
|
2020-03-15 05:12:47 +00:00
|
|
|
const files = glob.sync(`./antdv-demo/docs/${component}/demo/*.${suffix}`);
|
2018-05-13 15:11:51 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
files.forEach(file => {
|
|
|
|
let testMethod = options.skip === true ? test.skip : test;
|
2018-05-13 15:11:51 +00:00
|
|
|
if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) {
|
2019-01-12 03:33:27 +00:00
|
|
|
testMethod = test.skip;
|
2018-05-13 15:11:51 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
testMethod(`renders ${file} correctly`, done => {
|
|
|
|
MockDate.set(moment('2016-11-22'));
|
2020-03-07 11:45:13 +00:00
|
|
|
const demo = require(`../.${file}`).default || require(`../.${file}`);
|
2020-07-03 10:13:38 +00:00
|
|
|
document.body.innerHTML = '';
|
2020-08-12 12:26:09 +00:00
|
|
|
const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body });
|
2020-07-24 10:46:45 +00:00
|
|
|
nextTick(() => {
|
2020-03-07 11:45:13 +00: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 03:33:27 +00:00
|
|
|
MockDate.reset();
|
2020-08-12 12:26:09 +00:00
|
|
|
// wrapper.unmount();
|
2020-07-03 10:13:38 +00:00
|
|
|
document.body.innerHTML = '';
|
2019-01-12 03:33:27 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-13 15:11:51 +00:00
|
|
|
}
|