Browse Source

🐛 should not print warning for not generating help and validateStatus automatically when help or validateStatus is specified

close #14911
pull/15018/head
afc163 6 years ago
committed by 偏右
parent
commit
924e8e4b83
  1. 4
      components/form/FormItem.tsx
  2. 39
      components/form/__tests__/message.test.js

4
components/form/FormItem.tsx

@ -66,8 +66,10 @@ export default class FormItem extends React.Component<FormItemProps, any> {
helpShow = false; helpShow = false;
componentDidMount() { componentDidMount() {
const { children, help, validateStatus } = this.props;
warning( warning(
this.getControls(this.props.children, true).length <= 1, this.getControls(children, true).length <= 1 ||
(help !== undefined || validateStatus !== undefined),
'`Form.Item` cannot generate `validateStatus` and `help` automatically, ' + '`Form.Item` cannot generate `validateStatus` and `help` automatically, ' +
'while there are more than one `getFieldDecorator` in it.', 'while there are more than one `getFieldDecorator` in it.',
); );

39
components/form/__tests__/message.test.js

@ -87,4 +87,43 @@ describe('Form', () => {
expect(wrapper.render()).toMatchSnapshot(); expect(wrapper.render()).toMatchSnapshot();
}); });
it('should print warning for not generating help and validateStatus automatically', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const Form1 = Form.create()(({ form }) => {
return (
<Form>
<Form.Item label="Account">
{form.getFieldDecorator('account')(<input />)}
{form.getFieldDecorator('account')(<input />)}
</Form.Item>
</Form>
);
});
mount(<Form1 />);
expect(errorSpy).toBeCalledWith(
'Warning: `Form.Item` cannot generate `validateStatus` and `help` automatically, while there are more than one `getFieldDecorator` in it.',
);
errorSpy.mockRestore();
});
// https://github.com/ant-design/ant-design/issues/14911
it('should not print warning for not generating help and validateStatus automatically when help or validateStatus is specified', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const Form1 = Form.create()(({ form }) => {
return (
<Form>
<Form.Item label="Account" help="custom help information">
{form.getFieldDecorator('account')(<input />)}
{form.getFieldDecorator('account')(<input />)}
</Form.Item>
</Form>
);
});
mount(<Form1 />);
expect(errorSpy).not.toHaveBeenCalled();
errorSpy.mockRestore();
});
}); });

Loading…
Cancel
Save