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

31 lines
1.0 KiB
JavaScript
Raw Normal View History

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';
import Vue from 'vue';
import antd from 'ant-design-vue';
Vue.use(antd);
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';
const files = glob.sync(`./components/${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'));
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 14:04:10 +00:00
Vue.nextTick(() => {
2019-01-12 03:33:27 +00:00
expect(wrapper.html()).toMatchSnapshot();
MockDate.reset();
wrapper.destroy();
done();
});
});
});
2018-05-13 15:11:51 +00:00
}