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

31 lines
1.0 KiB
JavaScript
Raw Normal View History

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