diff --git a/.jest.js b/.jest.js
index 778b157c91..d162b283be 100644
--- a/.jest.js
+++ b/.jest.js
@@ -1,5 +1,3 @@
-const libDir = process.env.LIB_DIR;
-
const transformIgnorePatterns = [
'/dist/',
// Ignore modules without es dir.
@@ -7,6 +5,13 @@ const transformIgnorePatterns = [
'node_modules/(?!.*@babel)[^/]+?/(?!(es|node_modules)/)',
];
+function getTestRegex(libDir) {
+ if (libDir === 'dist') {
+ return 'demo\\.test\\.js$';
+ }
+ return '.*\\.test\\.(j|t)sx?$';
+}
+
module.exports = {
verbose: true,
setupFiles: ['./tests/setup.js'],
@@ -28,7 +33,7 @@ module.exports = {
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
- testRegex: `${libDir === 'dist' ? 'demo' : '.*'}\\.test\\.js$`,
+ testRegex: getTestRegex(process.env.LIB_DIR),
collectCoverageFrom: [
'components/**/*.{ts,tsx}',
'!components/*/style/index.tsx',
diff --git a/.jest.node.js b/.jest.node.js
index d91949fea1..1b76c15762 100644
--- a/.jest.node.js
+++ b/.jest.node.js
@@ -12,7 +12,7 @@ module.exports = {
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
- testRegex: 'demo\\.test\\.js$',
+ testRegex: 'demo\\.test\\.(j|t)s$',
testEnvironment: 'node',
transformIgnorePatterns,
snapshotSerializers: ['enzyme-to-json/serializer'],
diff --git a/components/button/__tests__/__snapshots__/demo.test.js.snap b/components/button/__tests__/__snapshots__/demo.test.ts.snap
similarity index 100%
rename from components/button/__tests__/__snapshots__/demo.test.js.snap
rename to components/button/__tests__/__snapshots__/demo.test.ts.snap
diff --git a/components/button/__tests__/__snapshots__/index.test.js.snap b/components/button/__tests__/__snapshots__/type.test.tsx.snap
similarity index 100%
rename from components/button/__tests__/__snapshots__/index.test.js.snap
rename to components/button/__tests__/__snapshots__/type.test.tsx.snap
diff --git a/components/button/__tests__/demo.test.js b/components/button/__tests__/demo.test.ts
similarity index 100%
rename from components/button/__tests__/demo.test.js
rename to components/button/__tests__/demo.test.ts
diff --git a/components/button/__tests__/index.test.js b/components/button/__tests__/type.test.tsx
similarity index 94%
rename from components/button/__tests__/index.test.js
rename to components/button/__tests__/type.test.tsx
index 425326aca5..1dd1443be9 100644
--- a/components/button/__tests__/index.test.js
+++ b/components/button/__tests__/type.test.tsx
@@ -1,12 +1,12 @@
import React, { Component } from 'react';
import { mount, render } from 'enzyme';
-import renderer from 'react-test-renderer';
import { SearchOutlined } from '@ant-design/icons';
import Button from '..';
import ConfigProvider from '../../config-provider';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { sleep } from '../../../tests/utils';
+import { SizeType } from '../../config-provider/SizeContext';
describe('Button', () => {
mountTest(Button);
@@ -30,13 +30,14 @@ describe('Button', () => {
});
it('mount correctly', () => {
- expect(() => renderer.create()).not.toThrow();
+ expect(() => mount()).not.toThrow();
});
it('warns if size is wrong', () => {
const mockWarn = jest.fn();
jest.spyOn(console, 'warn').mockImplementation(mockWarn);
- render();
+ const size = ('who am I' as any) as SizeType;
+ render();
expect(mockWarn).toHaveBeenCalledTimes(1);
expect(mockWarn.mock.calls[0][0]).toMatchObject({
message: 'unreachable case: "who am I"',
@@ -74,7 +75,7 @@ describe('Button', () => {
});
it('renders Chinese characters correctly in HOC', () => {
- const Text = ({ children }) => {children};
+ const Text = ({ children }: { children: React.ReactNode }) => {children};
const wrapper = mount(