|
1 | 1 | /* eslint-disable no-template-curly-in-string */
|
2 | 2 | import React from 'react';
|
3 | 3 | import { mount } from 'enzyme';
|
| 4 | +import { act } from 'react-dom/test-utils'; |
4 | 5 | import Form, { Field, useForm } from '../src';
|
5 | 6 | import InfoField, { Input } from './common/InfoField';
|
6 | 7 | import { changeValue, matchError, getField } from './common';
|
@@ -686,5 +687,40 @@ describe('Form.Validate', () => {
|
686 | 687 | expect(failedTriggerTimes).toEqual(1);
|
687 | 688 | expect(passedTriggerTimes).toEqual(1);
|
688 | 689 | });
|
| 690 | + |
| 691 | + it('validate support recursive', async () => { |
| 692 | + let form; |
| 693 | + const wrapper = mount( |
| 694 | + <div> |
| 695 | + <Form |
| 696 | + ref={instance => { |
| 697 | + form = instance; |
| 698 | + }} |
| 699 | + > |
| 700 | + <InfoField name={['username', 'do']} rules={[{ required: true }]} /> |
| 701 | + <InfoField name={['username', 'list']} rules={[{ required: true }]} /> |
| 702 | + </Form> |
| 703 | + </div>, |
| 704 | + ); |
| 705 | + |
| 706 | + wrapper |
| 707 | + .find('input') |
| 708 | + .at(0) |
| 709 | + .simulate('change', { target: { value: '' } }); |
| 710 | + await act(async () => { |
| 711 | + await timeout(); |
| 712 | + }); |
| 713 | + wrapper.update(); |
| 714 | + |
| 715 | + try { |
| 716 | + const values = await form.validateFields(['username'], { recursive: true }); |
| 717 | + expect(values.username.do).toBe(''); |
| 718 | + } catch (error) { |
| 719 | + expect(error.errorFields.length).toBe(2); |
| 720 | + } |
| 721 | + |
| 722 | + const values = await form.validateFields(['username']); |
| 723 | + expect(values.username.do).toBe(''); |
| 724 | + }); |
689 | 725 | });
|
690 | 726 | /* eslint-enable no-template-curly-in-string */
|
0 commit comments