Skip to content

Commit 9a72b49

Browse files
committed
test: test driven
1 parent fa2483d commit 9a72b49

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/dependencies.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,30 @@ describe('Form.Dependencies', () => {
268268
expect(container.querySelectorAll('input')).toHaveLength(1);
269269
expect(counter).toEqual(1);
270270
});
271+
272+
it('error should be cleared when dependency field changes and rule becomes false', async () => {
273+
const Demo = () => {
274+
const [form] = Form.useForm();
275+
const type = Form.useWatch('type', form);
276+
277+
return (
278+
<Form form={form}>
279+
<InfoField name="type">
280+
<Input />
281+
</InfoField>
282+
<InfoField name="name" rules={[{ required: type !== '1' }]}>
283+
<Input />
284+
</InfoField>
285+
</Form>
286+
);
287+
};
288+
289+
const { container } = render(<Demo />);
290+
await changeValue(getInput(container, 1), ['bamboo', '']);
291+
matchError(container, true);
292+
293+
// Change type to make rule true
294+
await changeValue(getInput(container), '1');
295+
matchError(container, false);
296+
});
271297
});

0 commit comments

Comments
 (0)