MCPcopy Create free account
hub / github.com/react-component/select / focusTest

Function focusTest

tests/shared/focusTest.tsx:7–72  ·  view source on GitHub ↗
(mode: any, props?: any)

Source from the content-addressed store, hash-verified

5import { render } from '@testing-library/react';
6
7export default function focusTest(mode: any, props?: any) {
8 describe(`focus of ${mode}`, () => {
9 let container;
10
11 beforeEach(() => {
12 container = document.createElement('div');
13 document.body.appendChild(container);
14 jest.useFakeTimers();
15 resetWarned();
16 });
17
18 afterEach(() => {
19 jest.useRealTimers();
20 });
21
22 it('focus()', () => {
23 const handleFocus = jest.fn();
24 const selectRef = React.createRef<any>();
25
26 render(
27 <div>
28 <Select ref={selectRef} mode={mode} {...props} onFocus={handleFocus}>
29 <Option value="1">1</Option>
30 <Option value="2">2</Option>
31 </Select>
32 </div>,
33 );
34
35 selectRef.current.focus();
36
37 expect(handleFocus).toHaveBeenCalled();
38 });
39
40 it('autoFocus', () => {
41 const handleFocus = jest.fn();
42
43 render(
44 <Select mode={mode} {...props} autoFocus onFocus={handleFocus}>
45 <Option value="1">1</Option>
46 <Option value="2">2</Option>
47 </Select>,
48 );
49
50 expect(handleFocus).toHaveBeenCalled();
51 });
52
53 // https://github.com/ant-design/ant-design/issues/14254
54 it('warning when `defaultOpen` is true but `autoFocus` not', () => {
55 const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
56 const handleFocus = jest.fn();
57
58 render(
59 <Select mode={mode} {...props} defaultOpen onFocus={handleFocus}>
60 <Option value="1">1</Option>
61 <Option value="2">2</Option>
62 </Select>,
63 );
64

Callers 4

Combobox.test.tsxFile · 0.85
Select.test.tsxFile · 0.85
Tags.test.tsxFile · 0.85
Multiple.test.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…