Browse Source

fix warning check logic (#15251)

pull/15256/head
zombieJ 6 years ago
committed by GitHub
parent
commit
dd435afadb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/input/Input.tsx
  2. 37
      components/input/__tests__/index.test.js

2
components/input/Input.tsx

@ -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');

37
components/input/__tests__/index.test.js

@ -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);

Loading…
Cancel
Save