2016-11-22 13:43:53 +08:00
|
|
|
import glob from 'glob'
|
|
|
|
import { render } from 'enzyme';
|
|
|
|
import { renderToJson } from 'enzyme-to-json';
|
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 testMethod = options.skip ? test.skip : test;
|
|
|
|
const files = glob.sync(`./components/${component}/demo/*.md`);
|
|
|
|
|
|
|
|
files.forEach(file => {
|
|
|
|
testMethod(`renders ${file} correctly`, () => {
|
2016-11-23 12:13:36 +08:00
|
|
|
MockDate.set(1479772800000); // 2016-11-22
|
2016-11-22 13:43:53 +08:00
|
|
|
const demo = require('../.' + file);
|
|
|
|
const wrapper = render(demo);
|
|
|
|
expect(renderToJson(wrapper)).toMatchSnapshot();
|
2016-11-23 12:13:36 +08:00
|
|
|
MockDate.reset();
|
2016-11-22 13:43:53 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|