Skip to content

Commit 3282cba

Browse files
committed
feat: add test
1 parent 7ffbcb0 commit 3282cba

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/list.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,4 +1000,35 @@ describe('Form.List', () => {
10001000
});
10011001
expect(valueRef.current).toEqual({ users: [{ name: 'a' }, { name: 'b' }] });
10021002
});
1003+
1004+
it('list rules', async () => {
1005+
const onFinishFailed = jest.fn();
1006+
1007+
const Demo = () => {
1008+
return (
1009+
<Form onFinishFailed={onFinishFailed}>
1010+
<Form.List name="users" rules={[{ validator: () => Promise.reject('error') }]}>
1011+
{fields => {
1012+
return fields.map(field => (
1013+
<InfoField name={[field.name, 'name']} key={field.key}>
1014+
<Input />
1015+
</InfoField>
1016+
));
1017+
}}
1018+
</Form.List>
1019+
<button type="submit" data-testid="submit">
1020+
Submit
1021+
</button>
1022+
</Form>
1023+
);
1024+
};
1025+
1026+
const { queryByTestId } = render(<Demo />);
1027+
fireEvent.click(queryByTestId('submit'));
1028+
await act(async () => {
1029+
await timeout();
1030+
});
1031+
1032+
expect(onFinishFailed).toHaveBeenCalled();
1033+
});
10031034
});

0 commit comments

Comments
 (0)