test: Raise coverage (#32182)

* chore: rm useless code

* test: Coverage of warningOnly

* test: 100% coverage
This commit is contained in:
二货机器人 2021-09-15 17:13:51 +08:00 committed by GitHub
parent 968590e8d0
commit bc9c2734dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View File

@ -873,4 +873,61 @@ describe('Form', () => {
expect(tooltipProps.title).toEqual('Bamboo');
});
});
it('warningOnly validate', async () => {
jest.useFakeTimers();
const wrapper = mount(
<Form>
<Form.Item>
<Form.Item name="test" rules={[{ required: true, warningOnly: true }]}>
<Input />
</Form.Item>
</Form.Item>
</Form>,
);
await change(wrapper, 0, '', true);
expect(wrapper.find('.ant-form-item-with-help').length).toBeTruthy();
expect(wrapper.find('.ant-form-item-has-warning').length).toBeTruthy();
jest.useRealTimers();
});
it('not warning when remove on validate', async () => {
jest.useFakeTimers();
let rejectFn = null;
const wrapper = mount(
<Form>
<Form.Item>
<Form.Item
noStyle
name="test"
rules={[
{
validator: () =>
new Promise((_, reject) => {
rejectFn = reject;
}),
},
]}
>
<Input />
</Form.Item>
</Form.Item>
</Form>,
);
await change(wrapper, 0, '', true);
wrapper.unmount();
// Delay validate failed
rejectFn(new Error('delay failed'));
expect(errorSpy).not.toHaveBeenCalled();
jest.useRealTimers();
});
});

View File

@ -122,7 +122,7 @@ const Col = React.forwardRef<HTMLDivElement, ColProps>((props, ref) => {
// Hack for Firefox to avoid size issue
// https://github.com/ant-design/ant-design/pull/20023#issuecomment-564389553
if (flex && wrap === false && !mergedStyle.minWidth) {
if (wrap === false && !mergedStyle.minWidth) {
mergedStyle.minWidth = 0;
}
}