ant-design/components/__tests__/node.test.tsx
二货爱吃白萝卜 1fc374495f
chore: patch for missing rootClassName (#40217)
* chore: init test

* test: rootClassName inject

* test: part of test

* chore: patch qrcode rootCls

* chore: part rootClassName

* chore: part rootClassName

* test: more test

* test: more test

* test: more test

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* test: more test

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: part rootClassName

* chore: fix lint

* chore: fix lint

* chore: ignore part of lint

* test: update snapshot

* test: fix test case

* chore: fix node test

* chore: adjust render logic

* fix: test

* test: update snapshot

* test: update

* refactor

* chore: fix require module logic
2023-01-20 11:03:50 +08:00

51 lines
1.6 KiB
TypeScript

import glob from 'glob';
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';
(global as any).testConfig = {};
jest.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
(global as any).testConfig[name] = option;
}
fakeDemoTest.rootPropsTest = () => {};
return fakeDemoTest;
});
describe('node', () => {
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});
// Find the component exist demo test file
const files = glob.sync(`./components/*/__tests__/demo.test.@(j|t)s?(x)`);
files.forEach((componentTestFile) => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];
// Test for ssr
describe(componentName, () => {
const demoList = glob.sync(`./components/${componentName}/demo/*.tsx`);
// Use mock to get config
require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require
const option = (global as any).testConfig?.[componentName];
demoList.forEach((demoFile) => {
const skip: string[] = option?.skip || [];
const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it;
test(demoFile, () => {
const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
});
});
});
});
});