ant-design/components/input/__tests__/index.test.js

23 lines
684 B
JavaScript
Raw Normal View History

2017-01-30 20:05:47 +08:00
import React from 'react';
import { mount } from 'enzyme';
import Input from '..';
2017-07-07 20:26:08 +08:00
const { TextArea } = Input;
2017-01-30 20:05:47 +08:00
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
2017-07-07 20:26:08 +08:00
describe('TextArea', () => {
2017-01-30 20:05:47 +08:00
it('should auto calculate height according to content length', async () => {
const wrapper = mount(
2017-07-07 20:26:08 +08:00
<TextArea value="" readOnly autosize />
2017-01-30 20:05:47 +08:00
);
2017-07-07 20:26:08 +08:00
const mockFunc = jest.spyOn(wrapper.node, 'resizeTextarea');
2017-01-30 20:05:47 +08:00
wrapper.setProps({ value: '1111\n2222\n3333' });
await delay(0);
2017-07-07 20:26:08 +08:00
expect(mockFunc).toHaveBeenCalledTimes(1);
2017-01-30 20:05:47 +08:00
wrapper.setProps({ value: '1111' });
await delay(0);
2017-07-07 20:26:08 +08:00
expect(mockFunc).toHaveBeenCalledTimes(2);
2017-01-30 20:05:47 +08:00
});
});