fix warning check logic (#15251)

This commit is contained in:
zombieJ 2019-03-07 15:47:43 +08:00 committed by GitHub
parent 01cf2114cc
commit dd435afadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -20,7 +20,7 @@ function fixControlledValue<T>(value: T) {
}
function hasPrefixSuffix(props: InputProps) {
return 'prefix' in props || props.suffix || props.allowClear;
return !!('prefix' in props || props.suffix || props.allowClear);
}
const InputSizes = tuple('small', 'default', 'large');

View File

@ -9,6 +9,16 @@ import calculateNodeHeight, { calculateNodeStyling } from '../calculateNodeHeigh
const { TextArea } = Input;
describe('Input', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
afterEach(() => {
errorSpy.mockReset();
});
afterAll(() => {
errorSpy.mockRestore();
});
focusTest(Input);
it('should support maxLength', () => {
@ -20,6 +30,33 @@ describe('Input', () => {
const wrapper = mount(<Input />);
wrapper.instance().select();
});
describe('focus trigger warning', () => {
it('not trigger', () => {
const wrapper = mount(<Input suffix="bamboo" />);
wrapper
.find('input')
.instance()
.focus();
wrapper.setProps({
suffix: 'light',
});
expect(errorSpy).not.toBeCalled();
});
it('trigger warning', () => {
const wrapper = mount(<Input />);
wrapper
.find('input')
.instance()
.focus();
wrapper.setProps({
suffix: 'light',
});
expect(errorSpy).toBeCalledWith(
'Warning: [antd: Input] When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ',
);
});
});
});
focusTest(TextArea);