mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
✅ Add test case for AutoComplete
This commit is contained in:
parent
f4a92d0997
commit
94db815765
@ -13,9 +13,11 @@ export default class InputElement extends React.Component<InputElementProps, any
|
||||
? this.ele.focus()
|
||||
: (ReactDOM.findDOMNode(this.ele) as HTMLInputElement).focus();
|
||||
};
|
||||
|
||||
blur = () => {
|
||||
this.ele.blur ? this.ele.blur() : (ReactDOM.findDOMNode(this.ele) as HTMLInputElement).blur();
|
||||
};
|
||||
|
||||
saveRef = (ele: HTMLInputElement) => {
|
||||
this.ele = ele;
|
||||
const { ref: childRef } = this.props.children as any;
|
||||
@ -23,6 +25,7 @@ export default class InputElement extends React.Component<InputElementProps, any
|
||||
childRef(ele);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return React.cloneElement(
|
||||
this.props.children,
|
||||
|
50
components/auto-complete/__tests__/focus.test.js
Normal file
50
components/auto-complete/__tests__/focus.test.js
Normal file
@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import AutoComplete from '..';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
|
||||
describe('AutoComplete could be focus', () => {
|
||||
focusTest(AutoComplete);
|
||||
});
|
||||
|
||||
describe('AutoComplete children could be focus', () => {
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
let container;
|
||||
beforeEach(() => {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(container);
|
||||
});
|
||||
|
||||
it('focus() and onFocus', () => {
|
||||
const handleFocus = jest.fn();
|
||||
const wrapper = mount(
|
||||
<AutoComplete onFocus={handleFocus} />
|
||||
, { attachTo: container });
|
||||
wrapper.find('input').instance().focus();
|
||||
jest.runAllTimers();
|
||||
expect(handleFocus).toBeCalled();
|
||||
});
|
||||
|
||||
it('blur() and onBlur', () => {
|
||||
const handleBlur = jest.fn();
|
||||
const wrapper = mount(
|
||||
<AutoComplete onBlur={handleBlur} />
|
||||
, { attachTo: container });
|
||||
wrapper.find('input').instance().focus();
|
||||
jest.runAllTimers();
|
||||
wrapper.find('input').instance().blur();
|
||||
jest.runAllTimers();
|
||||
expect(handleBlur).toBeCalled();
|
||||
});
|
||||
});
|
@ -1,11 +1,8 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import AutoComplete from '..';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
|
||||
describe('AutoComplete with Custom Input Element Render', () => {
|
||||
focusTest(AutoComplete);
|
||||
|
||||
it('AutoComplete with custom Input render perfectly', () => {
|
||||
const wrapper = mount(
|
||||
<AutoComplete dataSource={['12345', '23456', '34567']}>
|
||||
|
Loading…
Reference in New Issue
Block a user