import React from 'react'; import { mount } from 'enzyme'; // eslint-disable-next-line import/no-unresolved import Form from '../../form'; import Input from '..'; import focusTest from '../../../tests/shared/focusTest'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import calculateNodeHeight, { calculateNodeStyling } from '../calculateNodeHeight'; const { TextArea } = Input; describe('Input', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); afterEach(() => { errorSpy.mockReset(); }); afterAll(() => { errorSpy.mockRestore(); }); focusTest(Input); mountTest(Input); mountTest(Input.Group); rtlTest(Input); rtlTest(Input.Group); it('should support maxLength', () => { const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); it('select()', () => { const wrapper = mount(); wrapper.instance().select(); }); it('should support size', () => { const wrapper = mount(); expect(wrapper.find('input').hasClass('ant-input-lg')).toBe(true); expect(wrapper).toMatchSnapshot(); }); it('should support size in form', () => { const wrapper = mount(
, ); expect(wrapper.find('input').hasClass('ant-input-lg')).toBe(true); expect(wrapper).toMatchSnapshot(); }); describe('focus trigger warning', () => { it('not trigger', () => { const wrapper = mount(); wrapper .find('input') .instance() .focus(); wrapper.setProps({ suffix: 'light', }); expect(errorSpy).not.toHaveBeenCalled(); }); it('trigger warning', () => { const wrapper = mount(, { attachTo: document.body }); wrapper .find('input') .instance() .focus(); wrapper.setProps({ suffix: 'light', }); expect(errorSpy).toHaveBeenCalledWith( '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', ); wrapper.unmount(); }); }); }); focusTest(TextArea); describe('TextArea', () => { beforeAll(() => { jest.useFakeTimers(); }); afterAll(() => { jest.useRealTimers(); }); it('should auto calculate height according to content length', () => { const wrapper = mount(