import { mount } from 'enzyme'; import React from 'react'; import { act } from 'react-dom/test-utils'; import Form from '..'; import { sleep } 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 wrapper = mount(
{(fields, op) => { operation = op; return fields.map(field => ( )); }}
, ); // Add two async function addItem() { await act(async () => { operation!.add(); await sleep(100); jest.runAllTimers(); wrapper.update(); }); } addItem(); addItem(); // Submit await act(async () => { wrapper.find('form').simulate('submit'); await sleep(100); jest.runAllTimers(); wrapper.update(); }); // Remove first field await act(async () => { operation!.remove(0); await sleep(100); jest.runAllTimers(); wrapper.update(); }); // Match error message expect(wrapper.find('.ant-form-item-explain-error').text()).toEqual( "'users.1.first' is required", ); jest.useRealTimers(); }); });