Skip to content

Commit 1acf4f8

Browse files
committed
fix(Form): internal logic fixes * 4
1 parent 3d10229 commit 1acf4f8

File tree

6 files changed

+44
-42
lines changed

6 files changed

+44
-42
lines changed

src/components/fields/Checkbox/checkbox-group.test.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act, render, renderWithForm, userEvent } from '../../../test';
1+
import { render, renderWithForm, userEvent } from '../../../test';
22
import { Field, Checkbox } from '../../../index';
33

44
jest.mock('../../../_internal/hooks/use-warn');
@@ -20,17 +20,24 @@ describe('<CheckboxGroup />', () => {
2020

2121
it('should work with new <Form />', async () => {
2222
const { formInstance, getAllByRole } = renderWithForm(
23-
<Checkbox.Group defaultValue={['one']} label="test" name="test">
23+
<Checkbox.Group label="test" name="test">
2424
<Checkbox value="one">One</Checkbox>
2525
<Checkbox value="two">Two</Checkbox>
2626
</Checkbox.Group>,
27+
{
28+
formProps: {
29+
defaultValues: {
30+
test: ['one'],
31+
},
32+
},
33+
},
2734
);
2835
const checkbox = getAllByRole('checkbox');
2936

3037
expect(checkbox[0]).toBeChecked();
3138
expect(checkbox[1]).not.toBeChecked();
3239

33-
await act(async () => await userEvent.click(checkbox[1]));
40+
await userEvent.click(checkbox[1]);
3441

3542
expect(checkbox[0]).toBeChecked();
3643
expect(checkbox[1]).toBeChecked();
@@ -40,17 +47,24 @@ describe('<CheckboxGroup />', () => {
4047

4148
it('should interop with <Form />', async () => {
4249
const { getAllByRole, formInstance } = renderWithForm(
43-
<Field name="test" defaultValue={['two']}>
50+
<Field name="test">
4451
<Checkbox.Group label="test">
4552
<Checkbox value="one">Buy milk</Checkbox>
4653
<Checkbox value="two">Buy coffee</Checkbox>
4754
<Checkbox value="three">Buy bread</Checkbox>
4855
</Checkbox.Group>
4956
</Field>,
57+
{
58+
formProps: {
59+
defaultValues: {
60+
test: ['two'],
61+
},
62+
},
63+
},
5064
);
5165

5266
const checkbox = getAllByRole('checkbox');
53-
await act(async () => await userEvent.click(checkbox[0]));
67+
await userEvent.click(checkbox[0]);
5468

5569
expect(checkbox[0]).toBeChecked();
5670
expect(checkbox[1]).toBeChecked();

src/components/fields/Checkbox/checkbox.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import userEvent from '@testing-library/user-event';
22

3-
import { act, render, renderWithForm } from '../../../test';
3+
import { render, renderWithForm } from '../../../test';
44
import { Field } from '../../form';
55

66
import { Checkbox } from './Checkbox';
@@ -12,7 +12,7 @@ describe('<Checkbox />', () => {
1212
const { getByRole } = render(<Checkbox>Test</Checkbox>);
1313
const checkboxElement = getByRole('checkbox');
1414

15-
await act(async () => await userEvent.click(checkboxElement));
15+
await userEvent.click(checkboxElement);
1616

1717
expect(checkboxElement).toBeChecked();
1818
});
@@ -24,7 +24,7 @@ describe('<Checkbox />', () => {
2424

2525
const checkboxElement = getByRole('checkbox');
2626

27-
await act(async () => await userEvent.click(checkboxElement));
27+
await userEvent.click(checkboxElement);
2828

2929
expect(checkboxElement).toBeChecked();
3030
expect(formInstance.getFieldValue('test')).toBe(true);
@@ -39,7 +39,7 @@ describe('<Checkbox />', () => {
3939

4040
const checkboxElement = getByRole('checkbox');
4141

42-
await act(async () => await userEvent.click(checkboxElement));
42+
await userEvent.click(checkboxElement);
4343

4444
expect(checkboxElement).toBeChecked();
4545
expect(formInstance.getFieldValue('test')).toBe(true);

src/components/fields/RadioGroup/radio.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
act,
32
renderWithForm,
43
renderWithRoot,
54
screen,
@@ -19,7 +18,7 @@ describe('<Radio /> and <RadioGroup />', () => {
1918
</Radio.Group>,
2019
);
2120
const radio = getAllByRole('radio');
22-
await act(async () => await userEvent.click(radio[0]));
21+
await userEvent.click(radio[0]);
2322

2423
expect(radio[0]).toBeChecked();
2524
});
@@ -33,7 +32,7 @@ describe('<Radio /> and <RadioGroup />', () => {
3332
);
3433
const radio = screen.getAllByRole('radio');
3534

36-
await act(async () => await userEvent.click(radio[0]));
35+
await userEvent.click(radio[0]);
3736

3837
expect(radio[0]).toBeChecked();
3938

src/components/fields/Select/select.test.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
act,
3-
renderWithForm,
4-
renderWithRoot,
5-
userEvent,
6-
} from '../../../test/index';
1+
import { renderWithForm, renderWithRoot, userEvent } from '../../../test';
72
import { Field } from '../../form';
83

94
import { Select } from './Select';
@@ -21,10 +16,10 @@ describe('<Select />', () => {
2116
);
2217

2318
const select = getByRole('button');
24-
await act(async () => await userEvent.click(select));
19+
await userEvent.click(select);
2520

2621
const options = getAllByRole('option');
27-
await act(async () => await userEvent.click(options[1]));
22+
await userEvent.click(options[1]);
2823

2924
expect(select).toHaveTextContent('Red');
3025
});
@@ -41,10 +36,10 @@ describe('<Select />', () => {
4136
);
4237

4338
const select = getByRole('button');
44-
await act(async () => await userEvent.click(select));
39+
await userEvent.click(select);
4540

4641
const options = getAllByRole('option');
47-
await act(async () => await userEvent.click(options[1]));
42+
await userEvent.click(options[1]);
4843

4944
expect(select).toHaveTextContent('Red');
5045
expect(formInstance.getFieldValue('test')).toBe('2');
@@ -60,10 +55,10 @@ describe('<Select />', () => {
6055
);
6156

6257
const select = getByRole('button');
63-
await act(async () => await userEvent.click(select));
58+
await userEvent.click(select);
6459

6560
const options = getAllByRole('option');
66-
await act(async () => await userEvent.click(options[1]));
61+
await userEvent.click(options[1]);
6762

6863
expect(select).toHaveTextContent('Red');
6964
expect(formInstance.getFieldValue('test')).toBe('2');

src/components/fields/Switch/switch.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderWithForm, userEvent, render, act } from '../../../test';
1+
import { renderWithForm, userEvent, render } from '../../../test';
22
import { Field, Switch } from '../../../index';
33

44
jest.mock('../../../_internal/hooks/use-warn');
@@ -8,7 +8,7 @@ describe('<Switch />', () => {
88
const { getByRole } = render(<Switch aria-label="test" />);
99
const switchElement = getByRole('switch');
1010

11-
await act(async () => await userEvent.click(switchElement));
11+
await userEvent.click(switchElement);
1212

1313
expect(switchElement).toBeChecked();
1414
});
@@ -22,7 +22,7 @@ describe('<Switch />', () => {
2222

2323
const switchElement = getByRole('switch');
2424

25-
await act(async () => await userEvent.click(switchElement));
25+
await userEvent.click(switchElement);
2626

2727
expect(switchElement).toBeChecked();
2828
expect(formInstance.getFieldValue('test')).toBe(true);
@@ -35,7 +35,7 @@ describe('<Switch />', () => {
3535

3636
const switchElement = getByRole('switch');
3737

38-
await act(async () => await userEvent.click(switchElement));
38+
await userEvent.click(switchElement);
3939

4040
expect(switchElement).toBeChecked();
4141
expect(formInstance.getFieldValue('test')).toBe(true);

src/components/form/Form/submit-error.test.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import userEvents from '@testing-library/user-event';
2-
import { waitFor, act } from '@testing-library/react';
2+
import { waitFor } from '@testing-library/react';
33

44
import { renderWithForm } from '../../../test/index';
55
import { Submit } from '../../actions/index';
@@ -26,10 +26,8 @@ describe('<SubmitError />', () => {
2626
const submit = getByRole('button');
2727
const input = getByRole('textbox');
2828

29-
await act(async () => {
30-
await userEvents.type(input, 'test');
31-
await userEvents.click(submit);
32-
});
29+
await userEvents.type(input, 'test');
30+
await userEvents.click(submit);
3331

3432
await waitFor(() => {
3533
// onSubmitFailed callback should only be called if onSubmit callback is called and failed
@@ -63,10 +61,8 @@ describe('<SubmitError />', () => {
6361
const submit = getByRole('button');
6462
const input = getByRole('textbox');
6563

66-
await act(async () => {
67-
await userEvents.type(input, 'test');
68-
await userEvents.click(submit);
69-
});
64+
await userEvents.type(input, 'test');
65+
await userEvents.click(submit);
7066

7167
await waitFor(() => {
7268
// onSubmitFailed callback should only be called if onSubmit callback is called and failed
@@ -84,7 +80,7 @@ describe('<SubmitError />', () => {
8480
expect(submitErrorElement).toBeInTheDocument();
8581
});
8682

87-
await act(() => userEvents.type(input, 'changed'));
83+
await userEvents.type(input, 'changed');
8884

8985
await waitFor(() => {
9086
expect(submitErrorElement).not.toBeInTheDocument();
@@ -111,10 +107,8 @@ describe('<SubmitError />', () => {
111107
const submit = getByRole('button');
112108
const input = getByRole('textbox');
113109

114-
await act(async () => {
115-
await userEvents.type(input, 'test');
116-
await userEvents.click(submit);
117-
});
110+
await userEvents.type(input, 'test');
111+
await userEvents.click(submit);
118112

119113
await waitFor(() => {
120114
// onSubmitFailed callback should only be called if onSubmit callback is called and failed

0 commit comments

Comments
 (0)