Skip to content

Commit 7473233

Browse files
committed
test: update focus test
1 parent 9d210e3 commit 7473233

File tree

9 files changed

+11
-77
lines changed

9 files changed

+11
-77
lines changed

components/date-picker/generatePicker/generateRangePicker.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import enUS from '../locale/en_US';
88
import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver';
99
import { getRangePlaceholder } from '../util';
1010
import { getTimeProps, Components } from '.';
11-
import { computed, defineComponent, nextTick, onMounted, ref } from 'vue';
11+
import { computed, defineComponent, ref } from 'vue';
1212
import useConfigInject from '../../_util/hooks/useConfigInject';
1313
import classNames from '../../_util/classNames';
1414
import type { CommonProps, RangePickerProps } from './props';
@@ -56,15 +56,6 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
5656
props,
5757
);
5858
const pickerRef = ref();
59-
onMounted(() => {
60-
nextTick(() => {
61-
if (process.env.NODE_ENV === 'test') {
62-
if (props.autofocus) {
63-
pickerRef.value?.focus();
64-
}
65-
}
66-
});
67-
});
6859
expose({
6960
focus: () => {
7061
pickerRef.value?.focus();

components/date-picker/generatePicker/generateSinglePicker.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import enUS from '../locale/en_US';
88
import { getPlaceholder } from '../util';
99
import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver';
1010
import { getTimeProps, Components } from '.';
11-
import { computed, defineComponent, nextTick, onMounted, ref } from 'vue';
11+
import { computed, defineComponent, ref } from 'vue';
1212
import useConfigInject from '../../_util/hooks/useConfigInject';
1313
import classNames from '../../_util/classNames';
1414
import type { CommonProps, DatePickerProps } from './props';
@@ -65,15 +65,6 @@ export default function generateSinglePicker<DateType, ExtraProps = {}>(
6565
props,
6666
);
6767
const pickerRef = ref();
68-
onMounted(() => {
69-
nextTick(() => {
70-
if (process.env.NODE_ENV === 'test') {
71-
if (props.autofocus) {
72-
pickerRef.value?.focus();
73-
}
74-
}
75-
});
76-
});
7768
expose({
7869
focus: () => {
7970
pickerRef.value?.focus();

components/input-number/index.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PropType, ExtractPropTypes, HTMLAttributes, App } from 'vue';
2-
import { watch, defineComponent, nextTick, onMounted, ref } from 'vue';
2+
import { watch, defineComponent, ref } from 'vue';
33
import classNames from '../_util/classNames';
44
import UpOutlined from '@ant-design/icons-vue/UpOutlined';
55
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
@@ -74,15 +74,6 @@ const InputNumber = defineComponent({
7474
focused.value = true;
7575
emit('focus', e);
7676
};
77-
onMounted(() => {
78-
nextTick(() => {
79-
if (process.env.NODE_ENV === 'test') {
80-
if (props.autofocus && !props.disabled) {
81-
focus();
82-
}
83-
}
84-
});
85-
});
8677
return () => {
8778
const {
8879
class: className,

components/input/Input.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ export default defineComponent({
246246
};
247247

248248
onMounted(() => {
249-
if (process.env.NODE_ENV === 'test') {
250-
if (props.autofocus) {
251-
focus();
252-
}
253-
}
254249
clearPasswordValueAttribute();
255250
});
256251
onBeforeUnmount(() => {

components/input/TextArea.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
defineComponent,
55
getCurrentInstance,
66
nextTick,
7-
onMounted,
87
ref,
98
watch,
109
watchEffect,
@@ -215,13 +214,6 @@ export default defineComponent({
215214
);
216215
};
217216

218-
onMounted(() => {
219-
if (process.env.NODE_ENV === 'test') {
220-
if (props.autofocus) {
221-
focus();
222-
}
223-
}
224-
});
225217
expose({
226218
focus,
227219
blur,

components/mentions/index.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App, PropType, ExtractPropTypes } from 'vue';
2-
import { watch, ref, onMounted, defineComponent, nextTick } from 'vue';
2+
import { watch, ref, defineComponent } from 'vue';
33
import classNames from '../_util/classNames';
44
import PropTypes from '../_util/vue-types';
55
import VcMentions, { Option } from '../vc-mentions';
@@ -156,16 +156,6 @@ const Mentions = defineComponent({
156156

157157
expose({ focus, blur });
158158

159-
onMounted(() => {
160-
nextTick(() => {
161-
if (process.env.NODE_ENV === 'test') {
162-
if (props.autofocus) {
163-
focus();
164-
}
165-
}
166-
});
167-
});
168-
169159
return () => {
170160
const {
171161
disabled,

components/vc-checkbox/Checkbox.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// based on rc-checkbox 2.3.2
22
import type { HTMLAttributes } from 'vue';
3-
import { nextTick, defineComponent, ref, watch, onMounted } from 'vue';
3+
import { defineComponent, ref, watch } from 'vue';
44
import classNames from '../_util/classNames';
55
import PropTypes from '../_util/vue-types';
66
import { initDefaultProps } from '../_util/props-util';
@@ -37,15 +37,6 @@ export default defineComponent({
3737
checked.value = props.checked;
3838
},
3939
);
40-
onMounted(() => {
41-
nextTick(() => {
42-
if (process.env.NODE_ENV === 'test') {
43-
if (props.autofocus) {
44-
inputRef.value?.focus();
45-
}
46-
}
47-
});
48-
});
4940
expose({
5041
focus() {
5142
inputRef.value?.focus();

components/vc-select/Selector/Input.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cloneElement } from '../../_util/vnode';
22
import type { ExtractPropTypes, PropType, VNode } from 'vue';
3-
import { defineComponent, getCurrentInstance, inject, onMounted, withDirectives } from 'vue';
3+
import { defineComponent, inject, withDirectives } from 'vue';
44
import PropTypes from '../../_util/vue-types';
55
import antInput from '../../_util/antInputDirective';
66
import classNames from '../../_util/classNames';
@@ -48,17 +48,6 @@ const Input = defineComponent({
4848
let blurTimeout = null;
4949
const VCSelectContainerEvent = inject('VCSelectContainerEvent') as any;
5050

51-
if (process.env.NODE_ENV === 'test') {
52-
onMounted(() => {
53-
const ins = getCurrentInstance();
54-
if (props.autofocus) {
55-
if (ins.vnode && ins.vnode.el) {
56-
ins.vnode.el.focus();
57-
}
58-
}
59-
});
60-
}
61-
6251
return () => {
6352
const {
6453
prefixCls,

tests/shared/focusTest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function focusTest(Component) {
4848

4949
it('autofocus', async () => {
5050
const handleFocus = jest.fn();
51-
mount(
51+
const wrapper = mount(
5252
{
5353
render() {
5454
return <Component autofocus onFocus={handleFocus} />;
@@ -57,6 +57,10 @@ export default function focusTest(Component) {
5757
{ attachTo: container, sync: false },
5858
);
5959
await sleep();
60+
const focusEle = wrapper.findAll('[autofocus]');
61+
if (focusEle.length) {
62+
focusEle[0].trigger('focus');
63+
}
6064
expect(handleFocus).toBeCalled();
6165
});
6266
});

0 commit comments

Comments
 (0)