ant-design/components/form/__tests__/list-noStyle.test.tsx
lijianan 1885860e30
test: migrate part of form tests (#37727)
* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: migrate part of form tests

* test: Fix Form test case

* test: clean up

* test: add className describe

* test: add className describe

* test: add className describe

Co-authored-by: 二货机器人 <smith3816@gmail.com>
2022-09-26 09:54:52 +08:00

67 lines
1.6 KiB
TypeScript

import React from 'react';
import { act } from 'react-dom/test-utils';
import Form from '..';
import { render, fireEvent, waitFakeTimer } from '../../../tests/utils';
import Input from '../../input';
import type { FormListOperation } from '../FormList';
describe('Form.List.NoStyle', () => {
it('nest error should clean up', async () => {
jest.useFakeTimers();
let operation: FormListOperation;
const { container } = render(
<Form>
<Form.List name="users">
{(fields, op) => {
operation = op;
return fields.map(field => (
<Form.Item key={field.key}>
<Form.Item
{...field}
name={[field.name, 'first']}
rules={[{ required: true }]}
noStyle
>
<Input />
</Form.Item>
</Form.Item>
));
}}
</Form.List>
</Form>,
);
// Add two
const addItem = async () => {
await act(async () => {
operation?.add();
});
await waitFakeTimer();
};
await addItem();
await addItem();
// Submit
fireEvent.submit(container.querySelector('form')!);
await waitFakeTimer();
// Remove first field
await act(async () => {
operation?.remove(0);
});
await waitFakeTimer();
// Match error message
expect(container.querySelector('.ant-form-item-explain-error')?.textContent).toBe(
"'users.1.first' is required",
);
jest.clearAllTimers();
jest.useRealTimers();
});
});