mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +08:00
fix warning check logic (#15251)
This commit is contained in:
parent
01cf2114cc
commit
dd435afadb
@ -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');
|
||||
|
@ -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…
Reference in New Issue
Block a user