2016-12-08 11:08:13 +08:00
|
|
|
import glob from 'glob';
|
2016-11-22 13:43:53 +08:00
|
|
|
import { render } from 'enzyme';
|
2016-11-23 12:13:36 +08:00
|
|
|
import MockDate from 'mockdate';
|
2016-11-22 13:43:53 +08:00
|
|
|
|
|
|
|
export default function demoTest(component, options = {}) {
|
|
|
|
const files = glob.sync(`./components/${component}/demo/*.md`);
|
|
|
|
|
2016-12-08 11:08:13 +08:00
|
|
|
files.forEach((file) => {
|
2016-11-23 16:14:57 +08:00
|
|
|
let testMethod = options.skip === true ? test.skip : test;
|
2016-12-08 11:08:13 +08:00
|
|
|
if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) {
|
|
|
|
testMethod = test.skip;
|
|
|
|
}
|
2016-11-22 13:43:53 +08:00
|
|
|
testMethod(`renders ${file} correctly`, () => {
|
2016-12-08 11:08:13 +08:00
|
|
|
MockDate.set(new Date('2016-11-22').getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
|
|
|
|
const demo = require(`../.${file}`); // eslint-disable-line global-require, import/no-dynamic-require
|
2016-11-22 13:43:53 +08:00
|
|
|
const wrapper = render(demo);
|
2017-04-02 18:12:05 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2016-11-23 12:13:36 +08:00
|
|
|
MockDate.reset();
|
2016-11-22 13:43:53 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|