diff --git a/packages/vant/src/field/test/index.spec.js b/packages/vant/src/field/test/index.spec.js
index dd527cc83..676f8c3ae 100644
--- a/packages/vant/src/field/test/index.spec.js
+++ b/packages/vant/src/field/test/index.spec.js
@@ -1,5 +1,5 @@
import { Field } from '..';
-import { mount } from '../../../test';
+import { mount, later } from '../../../test';
test('should emit "update:modelValue" event when after inputting', () => {
const wrapper = mount(Field);
@@ -95,50 +95,51 @@ test('should format input value when type is digit', () => {
expect(wrapper.emitted('update:modelValue')[2][0]).toEqual('123');
});
-// TODO
-// test('should render textarea when type is textarea', async () => {
-// const wrapper = mount(Field, {
-// props: {
-// type: 'textarea',
-// autosize: true,
-// },
-// });
+test('should render textarea when type is textarea', async () => {
+ const wrapper = mount(Field, {
+ props: {
+ type: 'textarea',
+ autosize: true,
+ },
+ });
-// await later();
-// expect(wrapper.html()).toMatchSnapshot();
-// });
+ await later();
+ expect(wrapper.html()).toMatchSnapshot();
+});
-// test('autosize textarea field', () => {
-// const wrapper = mount(Field, {
-// props: {
-// type: 'textarea',
-// autosize: {},
-// },
-// });
+test('should autosize textarea field', async () => {
+ const wrapper = mount(Field, {
+ props: {
+ type: 'textarea',
+ autosize: {},
+ },
+ });
-// const value = '1'.repeat(20);
-// const textarea = wrapper.find('.van-field__control');
+ const value = '1'.repeat(20);
+ const textarea = wrapper.find('.van-field__control');
-// wrapper.setProps({ value });
-// expect(textarea.element.value).toEqual(value);
-// });
+ await wrapper.setProps({ modelValue: value });
+ expect(textarea.element.value).toEqual(value);
+});
-// test('autosize object', async () => {
-// const wrapper = mount(Field, {
-// props: {
-// type: 'textarea',
-// autosize: {
-// maxHeight: 100,
-// minHeight: 50,
-// },
-// },
-// });
+test('should allow autosize prop be be an object', async () => {
+ window.scrollTo = jest.fn();
-// const textarea = wrapper.find('.van-field__control');
+ const wrapper = mount(Field, {
+ props: {
+ type: 'textarea',
+ autosize: {
+ maxHeight: 100,
+ minHeight: 50,
+ },
+ },
+ });
-// await later();
-// expect(textarea.style.height).toEqual('50px');
-// });
+ const textarea = wrapper.find('.van-field__control');
+
+ await later();
+ expect(textarea.style.height).toEqual('50px');
+});
test('should call input.focus when vm.focus is called', () => {
const wrapper = mount(Field);
@@ -390,24 +391,18 @@ test('should render colon when using colon prop', () => {
expect(wrapper.find('.van-field__label').html()).toMatchSnapshot();
});
-// TODO
-// test('should blur search input on enter', () => {
-// const wrapper = mount(Field);
+test('should blur search input after pressing enter', async () => {
+ const wrapper = mount(Field, {
+ props: {
+ type: 'search',
+ },
+ });
-// wrapper.find('input').element.focus();
-// wrapper.find('input').trigger('keypress.enter');
-// expect(wrapper.emitted('blur')).toBeFalsy();
-
-// wrapper.setProps({ type: 'textarea' });
-// wrapper.find('textarea').element.focus();
-// wrapper.find('textarea').trigger('keypress.enter');
-// expect(wrapper.emitted('blur')).toBeFalsy();
-
-// wrapper.setProps({ type: 'search' });
-// wrapper.find('input').element.focus();
-// wrapper.find('input').trigger('keypress.enter');
-// expect(wrapper.emitted('blur')).toBeTruthy();
-// });
+ const onBlur = jest.fn();
+ wrapper.find('input').element.blur = onBlur;
+ await wrapper.find('input').trigger('keypress.enter');
+ expect(onBlur).toHaveBeenCalledTimes(1);
+});
test('should format value after mounted if initial modelValue is null', () => {
const wrapper = mount(Field, {