From 8bb10e4417ed6277ded7331afbcb025ff3c0fd8d Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 18 Oct 2021 17:54:54 +0800 Subject: [PATCH] test: fix some commented out test cases (#9691) * test: fix some commented out test cases * fix: remove log --- .../test/__snapshots__/index.spec.ts.snap | 10 ++ packages/vant/src/cascader/test/index.spec.ts | 27 +++-- packages/vant/src/circle/test/index.spec.ts | 21 ++-- .../test/__snapshots__/index.spec.js.snap | 13 +++ packages/vant/src/field/test/index.spec.js | 105 +++++++++--------- 5 files changed, 96 insertions(+), 80 deletions(-) diff --git a/packages/vant/src/cascader/test/__snapshots__/index.spec.ts.snap b/packages/vant/src/cascader/test/__snapshots__/index.spec.ts.snap index bca975355..66e1123dd 100644 --- a/packages/vant/src/cascader/test/__snapshots__/index.spec.ts.snap +++ b/packages/vant/src/cascader/test/__snapshots__/index.spec.ts.snap @@ -17,6 +17,16 @@ exports[`should render title slot correctly 1`] = ` `; +exports[`should select correct option when value changed 1`] = ` +
  • + + Wenzhou + + + +
  • +`; + exports[`should update tabs when previous tab is clicked 1`] = `
    diff --git a/packages/vant/src/cascader/test/index.spec.ts b/packages/vant/src/cascader/test/index.spec.ts index 62a9d78cf..64346f8dd 100644 --- a/packages/vant/src/cascader/test/index.spec.ts +++ b/packages/vant/src/cascader/test/index.spec.ts @@ -102,21 +102,20 @@ test('should render option slot correctly', async () => { expect(wrapper.find('.van-cascader__option').html()).toMatchSnapshot(); }); -// TODO -// test('should select correct option when value changed', async () => { -// const wrapper = mount(Cascader, { -// props: { -// options, -// }, -// }); +test('should select correct option when value changed', async () => { + const wrapper = mount(Cascader, { + props: { + options, + }, + }); -// await later(); -// await wrapper.setProps({ modelValue: '330304' }); -// await later(); -// const selectedOptions = wrapper.findAll('.van-cascader__option--selected'); -// const lastSelectedOption = selectedOptions[selectedOptions.length - 1]; -// expect(lastSelectedOption.html()).toMatchSnapshot(); -// }); + await later(); + await wrapper.setProps({ modelValue: '330304' }); + await later(); + const selectedOptions = wrapper.findAll('.van-cascader__option--selected'); + const lastSelectedOption = selectedOptions[selectedOptions.length - 1]; + expect(lastSelectedOption.html()).toMatchSnapshot(); +}); test('should reset selected options when value is set to empty', async () => { const wrapper = mount(Cascader, { diff --git a/packages/vant/src/circle/test/index.spec.ts b/packages/vant/src/circle/test/index.spec.ts index 219d6fcd6..3165f9f49 100644 --- a/packages/vant/src/circle/test/index.spec.ts +++ b/packages/vant/src/circle/test/index.spec.ts @@ -1,18 +1,17 @@ import { Circle } from '..'; import { mount, later } from '../../../test'; -// TODO -// test('should update to final rate immediately if speed is 0', async () => { -// const wrapper = mount(Circle, { -// props: { -// rate: 50, -// currentRate: 0, -// }, -// }); +test('should update to final rate immediately if speed is 0', async () => { + const wrapper = mount(Circle, { + props: { + rate: 50, + currentRate: 0, + }, + }); -// await later(); -// expect(wrapper.emitted('update:currentRate')).toBeTruthy(); -// }); + await later(); + expect(wrapper.emitted('update:currentRate')).toBeTruthy(); +}); test('should emit "update:currentRate" event during animation', async () => { const wrapper = mount(Circle, { diff --git a/packages/vant/src/field/test/__snapshots__/index.spec.js.snap b/packages/vant/src/field/test/__snapshots__/index.spec.js.snap index 43b62eb8f..26d40db5a 100644 --- a/packages/vant/src/field/test/__snapshots__/index.spec.js.snap +++ b/packages/vant/src/field/test/__snapshots__/index.spec.js.snap @@ -44,6 +44,19 @@ exports[`should render label slot correctly 1`] = `
    `; +exports[`should render textarea when type is textarea 1`] = ` +
    +
    +
    + +
    +
    +
    +`; + exports[`should render word limit correctly 1`] = `
    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, {