Skip to content

Commit 8c8a829

Browse files
authored
test: rm legacy react-dom/test-utils (#685)
1 parent 029abbb commit 8c8a829

File tree

4 files changed

+23
-36
lines changed

4 files changed

+23
-36
lines changed

tests/common/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { act } from 'react-dom/test-utils';
21
import timeout from './timeout';
32
import { matchNamePath } from '../../src/utils/valueUtil';
4-
import { fireEvent } from '@testing-library/react';
3+
import { fireEvent, act } from '@testing-library/react';
54

65
export function getInput(
76
container: HTMLElement,

tests/list.test.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import { act } from 'react-dom/test-utils';
3-
import { fireEvent, render } from '@testing-library/react';
2+
import { fireEvent, render, act } from '@testing-library/react';
43
import { resetWarned } from 'rc-util/lib/warning';
54
import Form, { Field, List } from '../src';
65
import type { FormProps } from '../src';
@@ -863,25 +862,23 @@ describe('Form.List', () => {
863862
<Form.List name="list">
864863
{(fields, { add }) => (
865864
<>
866-
{
867-
fields.map((field) => {
868-
return (
869-
<React.Fragment key={field.key}>
870-
<Form.Field name={[field.name, 'field1']}>
871-
<input placeholder="field1" />
872-
</Form.Field>
873-
<Form.Field name={[field.name, 'field2']}>
874-
<input placeholder="field2" />
875-
</Form.Field>
876-
</React.Fragment>
877-
);
878-
})
879-
}
865+
{fields.map(field => {
866+
return (
867+
<React.Fragment key={field.key}>
868+
<Form.Field name={[field.name, 'field1']}>
869+
<input placeholder="field1" />
870+
</Form.Field>
871+
<Form.Field name={[field.name, 'field2']}>
872+
<input placeholder="field2" />
873+
</Form.Field>
874+
</React.Fragment>
875+
);
876+
})}
880877
<button onClick={() => add()}>add</button>
881878
</>
882879
)}
883880
</Form.List>
884-
</Form>
881+
</Form>,
885882
);
886883

887884
expect(formRef.current.isFieldsTouched(true)).toBeFalsy();

tests/useWatch.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { useRef, useState } from 'react';
2-
import { render, fireEvent } from '@testing-library/react';
2+
import { render, fireEvent, act } from '@testing-library/react';
33
import type { FormInstance } from '../src';
44
import { List } from '../src';
55
import Form, { Field } from '../src';
66
import timeout from './common/timeout';
7-
import { act } from 'react-dom/test-utils';
87
import { Input } from './common/InfoField';
98
import { stringify } from '../src/useWatch';
109
import { changeValue } from './common';

tests/validate.test.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { fireEvent, render } from '@testing-library/react';
1+
import { fireEvent, render, act } from '@testing-library/react';
22
import React, { useEffect } from 'react';
3-
import { act } from 'react-dom/test-utils';
43
import Form, { Field, useForm } from '../src';
54
import type { FormInstance, ValidateMessages } from '../src/interface';
65
import { changeValue, getInput, matchError } from './common';
@@ -9,23 +8,19 @@ import timeout, { waitFakeTime } from './common/timeout';
98

109
describe('Form.Validate', () => {
1110
it('required', async () => {
12-
let form;
11+
const form = React.createRef<FormInstance>();
1312
const { container } = render(
1413
<div>
15-
<Form
16-
ref={instance => {
17-
form = instance;
18-
}}
19-
>
14+
<Form ref={form}>
2015
<InfoField name="username" rules={[{ required: true }]} />
2116
</Form>
2217
</div>,
2318
);
2419

2520
await changeValue(getInput(container), ['bamboo', '']);
2621
matchError(container, true);
27-
expect(form.getFieldError('username')).toEqual(["'username' is required"]);
28-
expect(form.getFieldsError()).toEqual([
22+
expect(form.current?.getFieldError('username')).toEqual(["'username' is required"]);
23+
expect(form.current?.getFieldsError()).toEqual([
2924
{
3025
name: ['username'],
3126
errors: ["'username' is required"],
@@ -34,7 +29,7 @@ describe('Form.Validate', () => {
3429
]);
3530

3631
// Contains not exists
37-
expect(form.getFieldsError(['username', 'not-exist'])).toEqual([
32+
expect(form.current?.getFieldsError(['username', 'not-exist'])).toEqual([
3833
{
3934
name: ['username'],
4035
errors: ["'username' is required"],
@@ -1075,11 +1070,8 @@ describe('Form.Validate', () => {
10751070
matchError(container.querySelectorAll<HTMLDivElement>('.field')[1], `validate`);
10761071
matchError(container.querySelectorAll<HTMLDivElement>('.field')[2], false);
10771072

1078-
10791073
// Revalidate
1080-
rerender(
1081-
<Demo touchMessage="new_touch" validateMessage="new_validate" />,
1082-
);
1074+
rerender(<Demo touchMessage="new_touch" validateMessage="new_validate" />);
10831075
formRef.current.validateFields({ dirty: true });
10841076

10851077
await waitFakeTime();

0 commit comments

Comments
 (0)