Skip to content

Commit bb9ec32

Browse files
committed
Migrate to testing-lib
1 parent 21c4884 commit bb9ec32

11 files changed

+203
-274
lines changed

jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Config } from 'jest';
2+
3+
const config: Config = {
4+
setupFilesAfterEnv: ['<rootDir>/tests/setupAfterEnv.ts'],
5+
};
6+
7+
export default config;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
},
5656
"devDependencies": {
5757
"@testing-library/jest-dom": "^5.16.4",
58-
"@testing-library/react": "^13.0.0",
58+
"@testing-library/react": "^12.1.5",
5959
"@types/enzyme": "^3.10.5",
60-
"@types/jest": "^26.0.20",
60+
"@types/jest": "^29.2.5",
6161
"@types/lodash": "^4.14.135",
6262
"@types/react": "^18.0.0",
6363
"@types/react-dom": "^18.0.0",
@@ -71,6 +71,7 @@
7171
"father": "^2.13.6",
7272
"father-build": "^1.18.6",
7373
"gh-pages": "^3.1.0",
74+
"jest": "^29.3.1",
7475
"np": "^5.0.3",
7576
"prettier": "^2.1.2",
7677
"react": "^16.14.0",

tests/legacy/clean-field.test.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { render } from '@testing-library/react';
3+
import type { FormInstance } from '../../src';
34
import Form, { Field } from '../../src';
45
import { Input } from '../common/InfoField';
56

67
describe('legacy.clean-field', () => {
78
// https://github.com/ant-design/ant-design/issues/12560
89
it('clean field if did update removed', async () => {
9-
let form;
10+
const form = React.createRef<FormInstance>();
1011

11-
const Test = ({ show }) => (
12-
<Form
13-
ref={instance => {
14-
form = instance;
15-
}}
16-
>
12+
const Test: React.FC<any> = ({ show }) => (
13+
<Form ref={form}>
1714
{show ? (
1815
<Field name="age" rules={[{ required: true }]}>
1916
<Input />
@@ -26,20 +23,20 @@ describe('legacy.clean-field', () => {
2623
</Form>
2724
);
2825

29-
const wrapper = mount(<Test show />);
26+
const { rerender } = render(<Test show />);
3027

3128
try {
32-
await form.validateFields();
29+
await form.current?.validateFields();
3330
throw new Error('should not pass');
3431
} catch ({ errorFields }) {
3532
expect(errorFields.length).toBe(1);
3633
expect(errorFields[0].name).toEqual(['age']);
3734
}
3835

39-
wrapper.setProps({ show: false });
36+
rerender(<Test show={false} />);
4037

4138
try {
42-
await form.validateFields();
39+
await form.current?.validateFields();
4340
throw new Error('should not pass');
4441
} catch ({ errorFields }) {
4542
expect(errorFields.length).toBe(1);

tests/legacy/dom-form.test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)