|
1 |
| -import React, { useState } from 'react'; |
| 1 | +import { act, fireEvent, render } from '@testing-library/react'; |
2 | 2 | import { resetWarned } from 'rc-util/lib/warning';
|
3 |
| -import Form, { Field, useForm, List, type FormInstance } from '../src'; |
4 |
| -import { Input } from './common/InfoField'; |
| 3 | +import React, { useState } from 'react'; |
| 4 | +import Form, { Field, List, useForm, type FormInstance } from '../src'; |
5 | 5 | import { changeValue, getInput } from './common';
|
6 |
| -import { act, fireEvent, render } from '@testing-library/react'; |
| 6 | +import { Input } from './common/InfoField'; |
7 | 7 |
|
8 | 8 | describe('Form.InitialValues', () => {
|
9 | 9 | it('works', () => {
|
@@ -382,4 +382,35 @@ describe('Form.InitialValues', () => {
|
382 | 382 | unmount();
|
383 | 383 | });
|
384 | 384 | });
|
| 385 | + |
| 386 | + it('should ignore in Form.List', () => { |
| 387 | + const { container } = render( |
| 388 | + <Form> |
| 389 | + <Form.List name="list"> |
| 390 | + {(fields, { add }) => ( |
| 391 | + <> |
| 392 | + <button |
| 393 | + onClick={() => { |
| 394 | + add(); |
| 395 | + }} |
| 396 | + /> |
| 397 | + {fields.map(field => ( |
| 398 | + <Field {...field} initialValue="bamboo" key={field.key}> |
| 399 | + <Input /> |
| 400 | + </Field> |
| 401 | + ))} |
| 402 | + </> |
| 403 | + )} |
| 404 | + </Form.List> |
| 405 | + </Form>, |
| 406 | + ); |
| 407 | + |
| 408 | + fireEvent.click(container.querySelector('button')); |
| 409 | + fireEvent.change(getInput(container), { target: { value: 'light' } }); |
| 410 | + expect(getInput(container).value).toEqual('light'); |
| 411 | + |
| 412 | + // Reset |
| 413 | + fireEvent.reset(container.querySelector('form')); |
| 414 | + expect(container.querySelectorAll('input')).toHaveLength(0); |
| 415 | + }); |
385 | 416 | });
|
0 commit comments