mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
9678d3fcfd
* Add test for select * Add focus() and blur() for AutoComplete * Add focus() and blur() to Cascader * Add focus test for input * Add focus() and blur() for Checkbox * Add focus() and blur() for Radio * Add focus() and blur() for Switch * Add blur() for TimePicker * Add focus() and blur() to TreeSelect
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
|
|
export default function focusTest(Component) {
|
|
describe('focus and blur', () => {
|
|
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(<Component onFocus={handleFocus} />, { attachTo: container });
|
|
wrapper.instance().focus();
|
|
jest.runAllTimers();
|
|
expect(handleFocus).toBeCalled();
|
|
});
|
|
|
|
it('blur() and onBlur', () => {
|
|
const handleBlur = jest.fn();
|
|
const wrapper = mount(<Component onBlur={handleBlur} />, { attachTo: container });
|
|
wrapper.instance().focus();
|
|
jest.runAllTimers();
|
|
wrapper.instance().blur();
|
|
jest.runAllTimers();
|
|
expect(handleBlur).toBeCalled();
|
|
});
|
|
|
|
it('autoFocus', () => {
|
|
const handleFocus = jest.fn();
|
|
mount(<Component autoFocus onFocus={handleFocus} />, { attachTo: container });
|
|
jest.runAllTimers();
|
|
expect(handleFocus).toBeCalled();
|
|
});
|
|
});
|
|
}
|