From e2e0f66fe6f1a38ccbc8d7d4cabc62981ae9b792 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Thu, 11 Feb 2021 13:04:00 +0800 Subject: [PATCH] types: test cases typing --- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 7 ++- src/address-list/test/index.spec.js | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 6 +-- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 6 +-- src/calendar/test/index.legacy.js | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 4 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 5 +- .../test/{index.spec.js => index.spec.tsx} | 47 ++++++++++++------- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 0 ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 4 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 2 +- src/collapse/index.tsx | 2 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 6 +-- .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- .../test/datetime-picker.legacy.js | 2 +- src/dialog/test/index.spec.js | 4 +- src/dropdown-menu/test/index.legacy.js | 4 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 4 +- src/field/test/index.spec.js | 2 +- src/grid/test/index.spec.js | 6 +-- src/icon/test/index.spec.js | 4 +- src/image-preview/test/index.spec.js | 4 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 6 +-- .../test/{index.spec.js => index.spec.ts} | 14 +++--- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 8 ++-- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- src/popover/test/index.spec.js | 4 +- src/popup/test/index.spec.js | 4 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- src/pull-refresh/index.tsx | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 2 +- src/radio/test/index.legacy.js | 2 +- src/rate/test/index.spec.js | 4 +- src/search/test/index.spec.js | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 0 src/sidebar/test/index.spec.js | 2 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 4 +- .../test/{index.spec.js => index.spec.ts} | 4 +- src/stepper/test/index.spec.js | 2 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 2 +- src/sticky/test/index.spec.js | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 6 +-- ...{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 8 ++-- src/tab/test/index.legacy.js | 2 +- ...index.spec.js.snap => index.spec.tsx.snap} | 0 .../test/{index.spec.js => index.spec.tsx} | 2 +- ...{index.spec.js.snap => index.spec.ts.snap} | 0 src/tag/test/{index.spec.js => index.spec.ts} | 2 +- src/toast/test/index.spec.js | 6 +-- src/tree-select/test/index.legacy.js | 2 +- test/event.ts | 13 +++-- 87 files changed, 129 insertions(+), 121 deletions(-) rename src/action-bar-button/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/action-bar-button/test/{index.spec.js => index.spec.ts} (84%) rename src/action-bar-icon/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/action-bar-icon/test/{index.spec.js => index.spec.ts} (95%) rename src/action-bar/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/action-bar/test/{index.spec.js => index.spec.ts} (85%) rename src/action-sheet/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/action-sheet/test/{index.spec.js => index.spec.ts} (97%) rename src/badge/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/badge/test/{index.spec.js => index.spec.ts} (90%) rename src/button/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/button/test/{index.spec.js => index.spec.ts} (91%) rename src/card/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/card/test/{index.spec.js => index.spec.ts} (97%) rename src/cascader/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/cascader/test/{index.spec.js => index.spec.ts} (98%) rename src/cell-group/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/cell-group/test/{index.spec.js => index.spec.ts} (84%) rename src/cell/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/cell/test/{index.spec.js => index.spec.ts} (93%) rename src/checkbox-group/test/{index.spec.js => index.spec.tsx} (74%) rename src/checkbox/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/checkbox/test/{index.spec.js => index.spec.ts} (100%) rename src/circle/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/circle/test/{index.spec.js => index.spec.ts} (90%) rename src/col/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/col/test/{index.spec.js => index.spec.tsx} (95%) rename src/collapse/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/collapse/test/{index.spec.js => index.spec.tsx} (98%) rename src/contact-card/test/{index.spec.js => index.spec.ts} (91%) rename src/contact-list/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/contact-list/test/{index.spec.js => index.spec.ts} (96%) rename src/empty/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/empty/test/{index.spec.js => index.spec.ts} (92%) rename src/image/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/image/test/{index.spec.js => index.spec.ts} (96%) rename src/loading/test/{index.spec.js => index.spec.ts} (72%) rename src/nav-bar/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/nav-bar/test/{index.spec.js => index.spec.ts} (97%) rename src/overlay/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/overlay/test/{index.spec.js => index.spec.tsx} (90%) rename src/pagination/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/pagination/test/{index.spec.js => index.spec.ts} (93%) rename src/password-input/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/password-input/test/{index.spec.js => index.spec.ts} (92%) rename src/progress/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/progress/test/{index.spec.js => index.spec.ts} (90%) rename src/pull-refresh/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/pull-refresh/test/{index.spec.js => index.spec.ts} (98%) rename src/share-sheet/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/share-sheet/test/{index.spec.js => index.spec.ts} (100%) rename src/skeleton/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/skeleton/test/{index.spec.js => index.spec.tsx} (93%) rename src/slider/test/{index.spec.js => index.spec.ts} (97%) rename src/steps/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/steps/test/{index.spec.js => index.spec.tsx} (98%) rename src/submit-bar/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/submit-bar/test/{index.spec.js => index.spec.ts} (95%) rename src/switch/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/switch/test/{index.spec.js => index.spec.ts} (92%) rename src/tabbar/test/__snapshots__/{index.spec.js.snap => index.spec.tsx.snap} (100%) rename src/tabbar/test/{index.spec.js => index.spec.tsx} (99%) rename src/tag/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/tag/test/{index.spec.js => index.spec.ts} (95%) diff --git a/src/action-bar-button/test/__snapshots__/index.spec.js.snap b/src/action-bar-button/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/action-bar-button/test/__snapshots__/index.spec.js.snap rename to src/action-bar-button/test/__snapshots__/index.spec.ts.snap diff --git a/src/action-bar-button/test/index.spec.js b/src/action-bar-button/test/index.spec.ts similarity index 84% rename from src/action-bar-button/test/index.spec.js rename to src/action-bar-button/test/index.spec.ts index 2445db33b..2a0a20fc0 100644 --- a/src/action-bar-button/test/index.spec.js +++ b/src/action-bar-button/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import ActionBarButton from '..'; test('should render default slot correctly', () => { diff --git a/src/action-bar-icon/test/__snapshots__/index.spec.js.snap b/src/action-bar-icon/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/action-bar-icon/test/__snapshots__/index.spec.js.snap rename to src/action-bar-icon/test/__snapshots__/index.spec.ts.snap diff --git a/src/action-bar-icon/test/index.spec.js b/src/action-bar-icon/test/index.spec.ts similarity index 95% rename from src/action-bar-icon/test/index.spec.js rename to src/action-bar-icon/test/index.spec.ts index d2bd315ab..b7695bba5 100644 --- a/src/action-bar-icon/test/index.spec.js +++ b/src/action-bar-icon/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import ActionBarIcon from '..'; test('should render default slot correctly', () => { diff --git a/src/action-bar/test/__snapshots__/index.spec.js.snap b/src/action-bar/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/action-bar/test/__snapshots__/index.spec.js.snap rename to src/action-bar/test/__snapshots__/index.spec.ts.snap diff --git a/src/action-bar/test/index.spec.js b/src/action-bar/test/index.spec.ts similarity index 85% rename from src/action-bar/test/index.spec.js rename to src/action-bar/test/index.spec.ts index 39e18b18d..dce48e5a2 100644 --- a/src/action-bar/test/index.spec.js +++ b/src/action-bar/test/index.spec.ts @@ -1,5 +1,5 @@ import ActionBar from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should allow to disable safe-area-inset-bottom prop', () => { const wrapper = mount(ActionBar, { diff --git a/src/action-sheet/test/__snapshots__/index.spec.js.snap b/src/action-sheet/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/action-sheet/test/__snapshots__/index.spec.js.snap rename to src/action-sheet/test/__snapshots__/index.spec.ts.snap diff --git a/src/action-sheet/test/index.spec.js b/src/action-sheet/test/index.spec.ts similarity index 97% rename from src/action-sheet/test/index.spec.js rename to src/action-sheet/test/index.spec.ts index bcfb9c645..592cdd6d2 100644 --- a/src/action-sheet/test/index.spec.js +++ b/src/action-sheet/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import ActionSheet from '..'; test('should emit select event after clicking option', () => { @@ -129,9 +129,8 @@ test('should change option color when using the color prop', () => { }, }); - expect(wrapper.find('.van-action-sheet__item').element.style.color).toEqual( - 'red' - ); + const item = wrapper.find('.van-action-sheet__item'); + expect(item.style.color).toEqual('red'); }); test('should hide close icon when the closeable prop is false', async () => { diff --git a/src/address-list/test/index.spec.js b/src/address-list/test/index.spec.js index ed297d8e5..e84813cdd 100644 --- a/src/address-list/test/index.spec.js +++ b/src/address-list/test/index.spec.js @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import AddressList from '..'; const list = [ diff --git a/src/badge/test/__snapshots__/index.spec.js.snap b/src/badge/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/badge/test/__snapshots__/index.spec.js.snap rename to src/badge/test/__snapshots__/index.spec.ts.snap diff --git a/src/badge/test/index.spec.js b/src/badge/test/index.spec.ts similarity index 90% rename from src/badge/test/index.spec.js rename to src/badge/test/index.spec.ts index af105d21b..e21272f0a 100644 --- a/src/badge/test/index.spec.js +++ b/src/badge/test/index.spec.ts @@ -1,5 +1,5 @@ import Badge from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render nothing when content is empty string', () => { const wrapper = mount(Badge, { @@ -52,7 +52,7 @@ test('should change dot position when using offset prop', () => { }, }); - const badge = wrapper.find('.van-badge').element; + const badge = wrapper.find('.van-badge'); expect(badge.style.top).toEqual('4px'); expect(badge.style.right).toEqual('-2px'); }); @@ -65,7 +65,7 @@ test('should change dot position when using offset prop without children', () => }, }); - const badge = wrapper.find('.van-badge').element; + const badge = wrapper.find('.van-badge'); expect(badge.style.marginTop).toEqual('4px'); expect(badge.style.marginLeft).toEqual('2px'); }); diff --git a/src/button/test/__snapshots__/index.spec.js.snap b/src/button/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/button/test/__snapshots__/index.spec.js.snap rename to src/button/test/__snapshots__/index.spec.ts.snap diff --git a/src/button/test/index.spec.js b/src/button/test/index.spec.ts similarity index 91% rename from src/button/test/index.spec.js rename to src/button/test/index.spec.ts index c2ed56cea..c28bdd0b3 100644 --- a/src/button/test/index.spec.js +++ b/src/button/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Button from '..'; test('should emit click event', () => { @@ -37,7 +37,7 @@ test('should hide border when color is gradient', () => { }, }); - expect(wrapper.element.style.border).toEqual('0px'); + expect(wrapper.style.border).toEqual('0px'); }); test('should change icon class prefix when using icon-prefix prop', () => { @@ -72,7 +72,7 @@ test('should render loading of a specific size when using loading-size prop', () }, }); - const loading = wrapper.find('.van-loading__spinner').element; + const loading = wrapper.find('.van-loading__spinner'); expect(loading.style.width).toEqual('10px'); expect(loading.style.height).toEqual('10px'); }); diff --git a/src/calendar/test/index.legacy.js b/src/calendar/test/index.legacy.js index eb496309e..9cf0dddf2 100644 --- a/src/calendar/test/index.legacy.js +++ b/src/calendar/test/index.legacy.js @@ -381,7 +381,7 @@ test('popup wrapper', async () => { expect(wrapper.html()).toMatchSnapshot(); wrapper.find('.van-popup__close-icon').trigger('click'); - expect(wrapper.element.style.display).toEqual('none'); + expect(wrapper.style.display).toEqual('none'); }); test('set show-mark prop to false', async () => { diff --git a/src/card/test/__snapshots__/index.spec.js.snap b/src/card/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/card/test/__snapshots__/index.spec.js.snap rename to src/card/test/__snapshots__/index.spec.ts.snap diff --git a/src/card/test/index.spec.js b/src/card/test/index.spec.ts similarity index 97% rename from src/card/test/index.spec.js rename to src/card/test/index.spec.ts index 2d3dc2514..5aace5531 100644 --- a/src/card/test/index.spec.js +++ b/src/card/test/index.spec.ts @@ -1,5 +1,5 @@ import Card from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit click event after clicked', () => { const onClick = jest.fn(); diff --git a/src/cascader/test/__snapshots__/index.spec.js.snap b/src/cascader/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/cascader/test/__snapshots__/index.spec.js.snap rename to src/cascader/test/__snapshots__/index.spec.ts.snap diff --git a/src/cascader/test/index.spec.js b/src/cascader/test/index.spec.ts similarity index 98% rename from src/cascader/test/index.spec.js rename to src/cascader/test/index.spec.ts index d79720034..8f3a25264 100644 --- a/src/cascader/test/index.spec.js +++ b/src/cascader/test/index.spec.ts @@ -1,6 +1,6 @@ import Cascader from '..'; -import { mount } from '@vue/test-utils'; -import { later } from '../../../test'; +import { mount , later } from '../../../test'; + import options from '../demo/area-en-US'; test('should emit change event when active option changed', async () => { diff --git a/src/cell-group/test/__snapshots__/index.spec.js.snap b/src/cell-group/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/cell-group/test/__snapshots__/index.spec.js.snap rename to src/cell-group/test/__snapshots__/index.spec.ts.snap diff --git a/src/cell-group/test/index.spec.js b/src/cell-group/test/index.spec.ts similarity index 84% rename from src/cell-group/test/index.spec.js rename to src/cell-group/test/index.spec.ts index a6c1a1c11..62f278c3e 100644 --- a/src/cell-group/test/index.spec.js +++ b/src/cell-group/test/index.spec.ts @@ -1,5 +1,5 @@ import CellGroup from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render title slot correctly', () => { const wrapper = mount(CellGroup, { diff --git a/src/cell/test/__snapshots__/index.spec.js.snap b/src/cell/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/cell/test/__snapshots__/index.spec.js.snap rename to src/cell/test/__snapshots__/index.spec.ts.snap diff --git a/src/cell/test/index.spec.js b/src/cell/test/index.spec.ts similarity index 93% rename from src/cell/test/index.spec.js rename to src/cell/test/index.spec.ts index 9da699b6b..898f02426 100644 --- a/src/cell/test/index.spec.js +++ b/src/cell/test/index.spec.ts @@ -1,5 +1,5 @@ import Cell from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render default slot correctly', () => { const wrapper = mount(Cell, { @@ -70,7 +70,8 @@ test('should change title style when using title-style prop', () => { }, }); - expect(wrapper.find('.van-cell__title').element.style.color).toEqual('red'); + const title = wrapper.find('.van-cell__title'); + expect(title.style.color).toEqual('red'); }); test('should change icon class prefix when using icon-prefix prop', () => { diff --git a/src/checkbox-group/test/index.spec.js b/src/checkbox-group/test/index.spec.tsx similarity index 74% rename from src/checkbox-group/test/index.spec.js rename to src/checkbox-group/test/index.spec.tsx index 47fa112d7..3ea95e245 100644 --- a/src/checkbox-group/test/index.spec.js +++ b/src/checkbox-group/test/index.spec.tsx @@ -1,7 +1,7 @@ -import { mount } from '@vue/test-utils'; -import Checkbox from '../../checkbox'; -import CheckboxGroup from '..'; import { ref, nextTick } from 'vue'; +import { mount } from '../../../test'; +import Checkbox from '../../checkbox'; +import CheckboxGroup, { CheckboxGroupToggleAllOptions } from '..'; test('should emit "update:modelValue" event when checkbox is clicked', async () => { const wrapper = mount({ @@ -45,8 +45,8 @@ test('should change icon size when using icon-size prop', () => { }); const icons = wrapper.findAll('.van-checkbox__icon'); - expect(icons[0].element.style.fontSize).toEqual('10rem'); - expect(icons[1].element.style.fontSize).toEqual('5rem'); + expect(icons[0].style.fontSize).toEqual('10rem'); + expect(icons[1].style.fontSize).toEqual('5rem'); }); test('should change checked color when using checked-color prop', () => { @@ -62,24 +62,30 @@ test('should change checked color when using checked-color prop', () => { }); const icons = wrapper.findAll('.van-icon'); - expect(icons[0].element.style.backgroundColor).toEqual('black'); - expect(icons[1].element.style.backgroundColor).toEqual('white'); + expect(icons[0].style.backgroundColor).toEqual('black'); + expect(icons[1].style.backgroundColor).toEqual('white'); }); test('should ignore Checkbox if bind-group is false', async () => { const wrapper = mount({ setup() { + const value = ref(false); + const groupRef = ref(); + const groupValue = ref([]); + const toggleAll = (checked?: boolean) => { + groupRef.value.toggleAll(checked); + }; + return { - value: ref(false), - groupValue: ref([]), - toggleAll(checked) { - this.$refs.group.toggleAll(checked); - }, + value, + groupRef, + groupValue, + toggleAll, }; }, render() { return ( - + @@ -100,16 +106,21 @@ test('should ignore Checkbox if bind-group is false', async () => { test('should toggle all checkboxes when toggleAll method is called', async () => { const wrapper = mount({ setup() { + const value = ref(['a']); + const groupRef = ref(); + const toggleAll = (options?: CheckboxGroupToggleAllOptions) => { + groupRef.value.toggleAll(options); + }; + return { - value: ref(['a']), - toggleAll(checked) { - this.$refs.group.toggleAll(checked); - }, + value, + groupRef, + toggleAll, }; }, render() { return ( - + diff --git a/src/checkbox/test/__snapshots__/index.spec.js.snap b/src/checkbox/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/checkbox/test/__snapshots__/index.spec.js.snap rename to src/checkbox/test/__snapshots__/index.spec.ts.snap diff --git a/src/checkbox/test/index.spec.js b/src/checkbox/test/index.spec.ts similarity index 100% rename from src/checkbox/test/index.spec.js rename to src/checkbox/test/index.spec.ts diff --git a/src/circle/test/__snapshots__/index.spec.js.snap b/src/circle/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/circle/test/__snapshots__/index.spec.js.snap rename to src/circle/test/__snapshots__/index.spec.ts.snap diff --git a/src/circle/test/index.spec.js b/src/circle/test/index.spec.ts similarity index 90% rename from src/circle/test/index.spec.js rename to src/circle/test/index.spec.ts index 0c2c14ec2..bfc9def70 100644 --- a/src/circle/test/index.spec.js +++ b/src/circle/test/index.spec.ts @@ -34,8 +34,8 @@ test('should change circle size when using size prop', () => { }, }); - expect(wrapper.element.style.width).toEqual('100px'); - expect(wrapper.element.style.height).toEqual('100px'); + expect(wrapper.style.width).toEqual('100px'); + expect(wrapper.style.height).toEqual('100px'); }); test('should change stroke linecap when using stroke-linecap prop', () => { diff --git a/src/col/test/__snapshots__/index.spec.js.snap b/src/col/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/col/test/__snapshots__/index.spec.js.snap rename to src/col/test/__snapshots__/index.spec.tsx.snap diff --git a/src/col/test/index.spec.js b/src/col/test/index.spec.tsx similarity index 95% rename from src/col/test/index.spec.js rename to src/col/test/index.spec.tsx index 8dea7eacc..3ac2ef5f4 100644 --- a/src/col/test/index.spec.js +++ b/src/col/test/index.spec.tsx @@ -1,6 +1,6 @@ import Col from '..'; import Row from '../../row'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render Col correcly', () => { const wrapper = mount(Col, { diff --git a/src/collapse/index.tsx b/src/collapse/index.tsx index 2bf967406..78d4b2f8e 100644 --- a/src/collapse/index.tsx +++ b/src/collapse/index.tsx @@ -19,7 +19,7 @@ export default createComponent({ type: [String, Number, Array] as PropType< string | number | Array >, - required: true, + default: '', }, border: { type: Boolean, diff --git a/src/collapse/test/__snapshots__/index.spec.js.snap b/src/collapse/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/collapse/test/__snapshots__/index.spec.js.snap rename to src/collapse/test/__snapshots__/index.spec.tsx.snap diff --git a/src/collapse/test/index.spec.js b/src/collapse/test/index.spec.tsx similarity index 98% rename from src/collapse/test/index.spec.js rename to src/collapse/test/index.spec.tsx index 9a45ad852..5eb41412b 100644 --- a/src/collapse/test/index.spec.js +++ b/src/collapse/test/index.spec.tsx @@ -1,9 +1,9 @@ -import { ref } from 'vue'; +import { defineComponent, ref } from 'vue'; import Collapse from '..'; import CollapseItem from '../../collapse-item'; import { later, mount } from '../../../test'; -const Component = { +const Component = defineComponent({ props: { accordion: Boolean, border: { @@ -31,7 +31,7 @@ const Component = { ); }, -}; +}); test('should update active value when title is clicked', async () => { const wrapper = mount(Component); diff --git a/src/contact-card/test/index.spec.js b/src/contact-card/test/index.spec.ts similarity index 91% rename from src/contact-card/test/index.spec.js rename to src/contact-card/test/index.spec.ts index 0bd871cbf..7a50cfb3d 100644 --- a/src/contact-card/test/index.spec.js +++ b/src/contact-card/test/index.spec.ts @@ -1,5 +1,5 @@ import ContactCard from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit click event when clicked', () => { const wrapper = mount(ContactCard); diff --git a/src/contact-list/test/__snapshots__/index.spec.js.snap b/src/contact-list/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/contact-list/test/__snapshots__/index.spec.js.snap rename to src/contact-list/test/__snapshots__/index.spec.ts.snap diff --git a/src/contact-list/test/index.spec.js b/src/contact-list/test/index.spec.ts similarity index 96% rename from src/contact-list/test/index.spec.js rename to src/contact-list/test/index.spec.ts index 078e59cd4..dd796c081 100644 --- a/src/contact-list/test/index.spec.js +++ b/src/contact-list/test/index.spec.ts @@ -1,5 +1,5 @@ import ContactList from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; const contactInfo = { name: 'jack', diff --git a/src/datetime-picker/test/datetime-picker.legacy.js b/src/datetime-picker/test/datetime-picker.legacy.js index 02b89b326..310d911c5 100644 --- a/src/datetime-picker/test/datetime-picker.legacy.js +++ b/src/datetime-picker/test/datetime-picker.legacy.js @@ -1,5 +1,5 @@ import DatetimePicker from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('confirm & cancel event', () => { const onConfirm = jest.fn(); diff --git a/src/dialog/test/index.spec.js b/src/dialog/test/index.spec.js index d19ae3010..c80e696b3 100644 --- a/src/dialog/test/index.spec.js +++ b/src/dialog/test/index.spec.js @@ -27,7 +27,7 @@ test('should change confirm button color when using confirm-button-color prop', }, }); const confirmButton = wrapper.find('.van-dialog__confirm'); - expect(confirmButton.element.style.color).toEqual('red'); + expect(confirmButton.style.color).toEqual('red'); }); test('should change cancel button color when using cancel-button-color prop', () => { @@ -39,7 +39,7 @@ test('should change cancel button color when using cancel-button-color prop', () }, }); const cancelButton = wrapper.find('.van-dialog__cancel'); - expect(cancelButton.element.style.color).toEqual('red'); + expect(cancelButton.style.color).toEqual('red'); }); test('should render button text correctly', () => { diff --git a/src/dropdown-menu/test/index.legacy.js b/src/dropdown-menu/test/index.legacy.js index 05988ad9c..370f6436e 100644 --- a/src/dropdown-menu/test/index.legacy.js +++ b/src/dropdown-menu/test/index.legacy.js @@ -226,12 +226,12 @@ test('toggle method', async (done) => { await later(); const content = wrapper.find('.van-dropdown-item__content'); - expect(content.element.style.display).toEqual(''); + expect(content.style.display).toEqual(''); // hide this.$refs.item.toggle(false, { immediate: true }); await later(); - expect(content.element.style.display).toEqual('none'); + expect(content.style.display).toEqual('none'); done(); }, diff --git a/src/empty/test/__snapshots__/index.spec.js.snap b/src/empty/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/empty/test/__snapshots__/index.spec.js.snap rename to src/empty/test/__snapshots__/index.spec.ts.snap diff --git a/src/empty/test/index.spec.js b/src/empty/test/index.spec.ts similarity index 92% rename from src/empty/test/index.spec.js rename to src/empty/test/index.spec.ts index ce52c2bf7..554dde581 100644 --- a/src/empty/test/index.spec.js +++ b/src/empty/test/index.spec.ts @@ -1,5 +1,5 @@ import Empty from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render image slot correctly', () => { const wrapper = mount(Empty, { @@ -48,7 +48,7 @@ test('should change image size when using image-size prop', async () => { }, }); - const image = wrapper.find('.van-empty__image').element; + const image = wrapper.find('.van-empty__image'); expect(image.style.width).toEqual('50px'); expect(image.style.height).toEqual('50px'); diff --git a/src/field/test/index.spec.js b/src/field/test/index.spec.js index e707db704..2e4209e99 100644 --- a/src/field/test/index.spec.js +++ b/src/field/test/index.spec.js @@ -137,7 +137,7 @@ test('should format input value when type is digit', () => { // const textarea = wrapper.find('.van-field__control'); // await later(); -// expect(textarea.element.style.height).toEqual('50px'); +// expect(textarea.style.height).toEqual('50px'); // }); test('should call input.focus when vm.focus is called', () => { diff --git a/src/grid/test/index.spec.js b/src/grid/test/index.spec.js index 7506c3b78..1baad5eca 100644 --- a/src/grid/test/index.spec.js +++ b/src/grid/test/index.spec.js @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Grid from '..'; import GridItem from '../../grid-item'; @@ -29,9 +29,7 @@ test('should change icon size when using icon-size prop', () => { }, }); - expect(wrapper.find('.van-grid-item__icon').element.style.fontSize).toEqual( - '10px' - ); + expect(wrapper.find('.van-grid-item__icon').style.fontSize).toEqual('10px'); }); test('should render icon-slot correctly', () => { diff --git a/src/icon/test/index.spec.js b/src/icon/test/index.spec.js index 50bcac59e..d4b17a981 100644 --- a/src/icon/test/index.spec.js +++ b/src/icon/test/index.spec.js @@ -1,5 +1,5 @@ import Icon from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should render icon with builtin icon name correctly', () => { const wrapper = mount(Icon, { @@ -73,5 +73,5 @@ test('should change icon size when using size prop', () => { size: 20, }, }); - expect(wrapper.element.style.fontSize).toEqual('20px'); + expect(wrapper.style.fontSize).toEqual('20px'); }); diff --git a/src/image-preview/test/index.spec.js b/src/image-preview/test/index.spec.js index 9fd936f1c..429032fae 100644 --- a/src/image-preview/test/index.spec.js +++ b/src/image-preview/test/index.spec.js @@ -1,6 +1,6 @@ -import { mount } from '@vue/test-utils'; +import { mount , later } from '../../../test'; import ImagePreviewComponent from '../ImagePreview'; -import { later } from '../../../test'; + import { trigger } from '../../utils'; const images = [ diff --git a/src/image/test/__snapshots__/index.spec.js.snap b/src/image/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/image/test/__snapshots__/index.spec.js.snap rename to src/image/test/__snapshots__/index.spec.ts.snap diff --git a/src/image/test/index.spec.js b/src/image/test/index.spec.ts similarity index 96% rename from src/image/test/index.spec.js rename to src/image/test/index.spec.ts index 49481d3ce..844b7a76e 100644 --- a/src/image/test/index.spec.js +++ b/src/image/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import VanImage from '..'; import Lazyload from '../../lazyload'; @@ -133,8 +133,8 @@ test('should change border radius when using border-radius prop', () => { }, }); - expect(wrapper.element.style.overflow).toEqual('hidden'); - expect(wrapper.element.style.borderRadius).toEqual('3px'); + expect(wrapper.style.overflow).toEqual('hidden'); + expect(wrapper.style.borderRadius).toEqual('3px'); }); test('should render default slot correctly', () => { diff --git a/src/loading/test/index.spec.js b/src/loading/test/index.spec.ts similarity index 72% rename from src/loading/test/index.spec.js rename to src/loading/test/index.spec.ts index 33b70c45a..0f2401f9f 100644 --- a/src/loading/test/index.spec.js +++ b/src/loading/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Loading from '..'; test('should change loading size when using size prop', () => { @@ -8,7 +8,7 @@ test('should change loading size when using size prop', () => { }, }); - const spinner = wrapper.find('.van-loading__spinner').element; + const spinner = wrapper.find('.van-loading__spinner'); expect(spinner.style.width).toEqual('20px'); expect(spinner.style.height).toEqual('20px'); }); @@ -23,9 +23,7 @@ test('should change text font-size when using text-size prop', () => { }, }); - expect(wrapper.find('.van-loading__text').element.style.fontSize).toEqual( - '20px' - ); + expect(wrapper.find('.van-loading__text').style.fontSize).toEqual('20px'); }); test('should change text color when using text-color prop', async () => { @@ -38,7 +36,7 @@ test('should change text color when using text-color prop', async () => { }, }); - expect(wrapper.find('.van-loading__text').element.style.color).toBe('red'); + expect(wrapper.find('.van-loading__text').style.color).toBe('red'); }); test('should change text color when using color prop', async () => { @@ -51,7 +49,7 @@ test('should change text color when using color prop', async () => { }, }); - expect(wrapper.find('.van-loading__text').element.style.color).toBe('green'); + expect(wrapper.find('.van-loading__text').style.color).toBe('green'); }); test('should change text color to textColor when using color & textColor prop', async () => { @@ -65,5 +63,5 @@ test('should change text color to textColor when using color & textColor prop', }, }); - expect(wrapper.find('.van-loading__text').element.style.color).toBe('red'); + expect(wrapper.find('.van-loading__text').style.color).toBe('red'); }); diff --git a/src/nav-bar/test/__snapshots__/index.spec.js.snap b/src/nav-bar/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/nav-bar/test/__snapshots__/index.spec.js.snap rename to src/nav-bar/test/__snapshots__/index.spec.ts.snap diff --git a/src/nav-bar/test/index.spec.js b/src/nav-bar/test/index.spec.ts similarity index 97% rename from src/nav-bar/test/index.spec.js rename to src/nav-bar/test/index.spec.ts index a662f0f35..6a3c0f587 100644 --- a/src/nav-bar/test/index.spec.js +++ b/src/nav-bar/test/index.spec.ts @@ -83,5 +83,5 @@ test('should change z-index when using z-index prop', () => { zIndex: 100, }, }); - expect(wrapper.element.style.zIndex).toEqual('100'); + expect(wrapper.style.zIndex).toEqual('100'); }); diff --git a/src/overlay/test/__snapshots__/index.spec.js.snap b/src/overlay/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/overlay/test/__snapshots__/index.spec.js.snap rename to src/overlay/test/__snapshots__/index.spec.tsx.snap diff --git a/src/overlay/test/index.spec.js b/src/overlay/test/index.spec.tsx similarity index 90% rename from src/overlay/test/index.spec.js rename to src/overlay/test/index.spec.tsx index e3a67af36..ed70b4b62 100644 --- a/src/overlay/test/index.spec.js +++ b/src/overlay/test/index.spec.tsx @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Overlay from '..'; test('should change z-index when using z-index prop', () => { @@ -9,7 +9,7 @@ test('should change z-index when using z-index prop', () => { }, }); - const overlay = wrapper.find('.van-overlay').element; + const overlay = wrapper.find('.van-overlay'); expect(overlay.style.zIndex).toEqual('99'); }); @@ -35,7 +35,7 @@ test('should allow to custom style with custom-style prop', () => { }, }); - const overlay = wrapper.find('.van-overlay').element; + const overlay = wrapper.find('.van-overlay'); expect(overlay.style.backgroundColor).toEqual('red'); }); @@ -47,7 +47,7 @@ test('should change animation duration when using duration prop', () => { }, }); - const overlay = wrapper.find('.van-overlay').element; + const overlay = wrapper.find('.van-overlay'); expect(overlay.style.animationDuration).toEqual('1s'); }); diff --git a/src/pagination/test/__snapshots__/index.spec.js.snap b/src/pagination/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/pagination/test/__snapshots__/index.spec.js.snap rename to src/pagination/test/__snapshots__/index.spec.ts.snap diff --git a/src/pagination/test/index.spec.js b/src/pagination/test/index.spec.ts similarity index 93% rename from src/pagination/test/index.spec.js rename to src/pagination/test/index.spec.ts index dcace6046..ad7ada5d8 100644 --- a/src/pagination/test/index.spec.js +++ b/src/pagination/test/index.spec.ts @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Paginaion from '..'; test('should render prev-text、next-text slot correctly', () => { diff --git a/src/password-input/test/__snapshots__/index.spec.js.snap b/src/password-input/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/password-input/test/__snapshots__/index.spec.js.snap rename to src/password-input/test/__snapshots__/index.spec.ts.snap diff --git a/src/password-input/test/index.spec.js b/src/password-input/test/index.spec.ts similarity index 92% rename from src/password-input/test/index.spec.js rename to src/password-input/test/index.spec.ts index 33ce961d3..aec3d7c26 100644 --- a/src/password-input/test/index.spec.js +++ b/src/password-input/test/index.spec.ts @@ -1,5 +1,5 @@ import PasswordInput from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit focus event when security is touched', () => { const wrapper = mount(PasswordInput); diff --git a/src/popover/test/index.spec.js b/src/popover/test/index.spec.js index 0dba113f8..962ae1a6f 100644 --- a/src/popover/test/index.spec.js +++ b/src/popover/test/index.spec.js @@ -91,9 +91,7 @@ test('should allow to custom the color of action test', () => { }, }); - expect(wrapper.find('.van-popover__action').element.style.color).toEqual( - 'red' - ); + expect(wrapper.find('.van-popover__action').style.color).toEqual('red'); }); test('should locate to reference element when showed', async () => { diff --git a/src/popup/test/index.spec.js b/src/popup/test/index.spec.js index ee1355356..6c9c8c6a1 100644 --- a/src/popup/test/index.spec.js +++ b/src/popup/test/index.spec.js @@ -29,8 +29,8 @@ test('should change z-index when using z-index prop', async () => { }); await nextTick(); - expect(wrapper.find('.van-popup').element.style.zIndex).toEqual('11'); - expect(wrapper.find('.van-overlay').element.style.zIndex).toEqual('11'); + expect(wrapper.find('.van-popup').style.zIndex).toEqual('11'); + expect(wrapper.find('.van-overlay').style.zIndex).toEqual('11'); }); test('should lock scroll when showed', async () => { diff --git a/src/progress/test/__snapshots__/index.spec.js.snap b/src/progress/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/progress/test/__snapshots__/index.spec.js.snap rename to src/progress/test/__snapshots__/index.spec.ts.snap diff --git a/src/progress/test/index.spec.js b/src/progress/test/index.spec.ts similarity index 90% rename from src/progress/test/index.spec.js rename to src/progress/test/index.spec.ts index c7e25e426..400d0979e 100644 --- a/src/progress/test/index.spec.js +++ b/src/progress/test/index.spec.ts @@ -25,5 +25,5 @@ test('should change track color when using track-color prop', () => { }, }); - expect(wrapper.element.style.background).toEqual('green'); + expect(wrapper.style.background).toEqual('green'); }); diff --git a/src/pull-refresh/index.tsx b/src/pull-refresh/index.tsx index c1db311d2..de96ac8f5 100644 --- a/src/pull-refresh/index.tsx +++ b/src/pull-refresh/index.tsx @@ -31,7 +31,7 @@ export default createComponent({ loadingText: String, modelValue: { type: Boolean, - required: true, + default: false, }, successDuration: { type: [Number, String], diff --git a/src/pull-refresh/test/__snapshots__/index.spec.js.snap b/src/pull-refresh/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/pull-refresh/test/__snapshots__/index.spec.js.snap rename to src/pull-refresh/test/__snapshots__/index.spec.ts.snap diff --git a/src/pull-refresh/test/index.spec.js b/src/pull-refresh/test/index.spec.ts similarity index 98% rename from src/pull-refresh/test/index.spec.js rename to src/pull-refresh/test/index.spec.ts index 4d0c494b0..2b2af224d 100644 --- a/src/pull-refresh/test/index.spec.js +++ b/src/pull-refresh/test/index.spec.ts @@ -148,5 +148,5 @@ test('should set height when using head-height', async () => { }, }); const head = wrapper.find('.van-pull-refresh__head'); - expect(head.element.style.height).toEqual('100px'); + expect(head.style.height).toEqual('100px'); }); diff --git a/src/radio/test/index.legacy.js b/src/radio/test/index.legacy.js index c14c2a7ca..05506f806 100644 --- a/src/radio/test/index.legacy.js +++ b/src/radio/test/index.legacy.js @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('radio-group change', () => { const wrapper = mount({ diff --git a/src/rate/test/index.spec.js b/src/rate/test/index.spec.js index 54f000477..bd3d189f6 100644 --- a/src/rate/test/index.spec.js +++ b/src/rate/test/index.spec.js @@ -112,9 +112,7 @@ test('should change icon size when using size prop', () => { }, }); - expect(wrapper.find('.van-rate__icon').element.style.fontSize).toEqual( - '2rem' - ); + expect(wrapper.find('.van-rate__icon').style.fontSize).toEqual('2rem'); }); test('should not emit change event when untouchable rate is touchmoved', () => { diff --git a/src/search/test/index.spec.js b/src/search/test/index.spec.js index 644d995b7..89999653a 100644 --- a/src/search/test/index.spec.js +++ b/src/search/test/index.spec.js @@ -1,5 +1,5 @@ import Search from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit update:modelValue event when input value changed', () => { const onUpdateModelValue = jest.fn(); diff --git a/src/share-sheet/test/__snapshots__/index.spec.js.snap b/src/share-sheet/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/share-sheet/test/__snapshots__/index.spec.js.snap rename to src/share-sheet/test/__snapshots__/index.spec.ts.snap diff --git a/src/share-sheet/test/index.spec.js b/src/share-sheet/test/index.spec.ts similarity index 100% rename from src/share-sheet/test/index.spec.js rename to src/share-sheet/test/index.spec.ts diff --git a/src/sidebar/test/index.spec.js b/src/sidebar/test/index.spec.js index f5700ce06..f1c46c319 100644 --- a/src/sidebar/test/index.spec.js +++ b/src/sidebar/test/index.spec.js @@ -1,5 +1,5 @@ import { ref } from 'vue'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Sidebar from '..'; import SidebarItem from '../../sidebar-item'; diff --git a/src/skeleton/test/__snapshots__/index.spec.js.snap b/src/skeleton/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/skeleton/test/__snapshots__/index.spec.js.snap rename to src/skeleton/test/__snapshots__/index.spec.tsx.snap diff --git a/src/skeleton/test/index.spec.js b/src/skeleton/test/index.spec.tsx similarity index 93% rename from src/skeleton/test/index.spec.js rename to src/skeleton/test/index.spec.tsx index 9c2f1ba15..8fbcb02c8 100644 --- a/src/skeleton/test/index.spec.js +++ b/src/skeleton/test/index.spec.tsx @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Skeleton from '..'; test('should render with row width array correctly', () => { @@ -30,7 +30,7 @@ test('should change avatar size when using avatar-size prop', () => { }, }); - const avatar = wrapper.find('.van-skeleton__avatar').element; + const avatar = wrapper.find('.van-skeleton__avatar'); expect(avatar.style.width).toMatchSnapshot('20rem'); expect(avatar.style.height).toMatchSnapshot('20ren'); }); diff --git a/src/slider/test/index.spec.js b/src/slider/test/index.spec.ts similarity index 97% rename from src/slider/test/index.spec.js rename to src/slider/test/index.spec.ts index 3a5dc1734..83d76c668 100644 --- a/src/slider/test/index.spec.js +++ b/src/slider/test/index.spec.ts @@ -141,7 +141,7 @@ test('should change slider bar height when using bar-height prop', () => { }, }); - expect(wrapper.element.style.height).toEqual('10px'); + expect(wrapper.style.height).toEqual('10px'); }); test('shoud change button size when using button-size prop', () => { @@ -152,7 +152,7 @@ test('shoud change button size when using button-size prop', () => { }, }); - const button = wrapper.find('.van-slider__button').element; + const button = wrapper.find('.van-slider__button'); expect(button.style.width).toEqual('10px'); expect(button.style.height).toEqual('10px'); }); diff --git a/src/stepper/test/index.spec.js b/src/stepper/test/index.spec.js index 8fd7fc1ae..d3e0b71da 100644 --- a/src/stepper/test/index.spec.js +++ b/src/stepper/test/index.spec.js @@ -252,7 +252,7 @@ test('should update input width when using input-width prop', () => { inputWidth: '10rem', }, }); - expect(wrapper.find('input').element.style.width).toEqual('10rem'); + expect(wrapper.find('input').style.width).toEqual('10rem'); }); test('should update input height and button size when using button-size prop', () => { diff --git a/src/steps/test/__snapshots__/index.spec.js.snap b/src/steps/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/steps/test/__snapshots__/index.spec.js.snap rename to src/steps/test/__snapshots__/index.spec.tsx.snap diff --git a/src/steps/test/index.spec.js b/src/steps/test/index.spec.tsx similarity index 98% rename from src/steps/test/index.spec.js rename to src/steps/test/index.spec.tsx index 408d29dcc..e98dc1b7e 100644 --- a/src/steps/test/index.spec.js +++ b/src/steps/test/index.spec.tsx @@ -1,4 +1,4 @@ -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; import Step from '../../step'; import Steps from '..'; diff --git a/src/sticky/test/index.spec.js b/src/sticky/test/index.spec.js index 2471acd47..0501a4a9d 100644 --- a/src/sticky/test/index.spec.js +++ b/src/sticky/test/index.spec.js @@ -321,7 +321,7 @@ test('should emit scroll event when visibility changed', async () => { observerCallback([{ intersectionRatio: 1 }]); expect(onScroll).toHaveBeenCalledTimes(2); - wrapper.element.style.display = 'none'; + wrapper.style.display = 'none'; observerCallback([{ intersectionRatio: 0 }]); expect(onScroll).toHaveBeenCalledTimes(2); diff --git a/src/submit-bar/test/__snapshots__/index.spec.js.snap b/src/submit-bar/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/submit-bar/test/__snapshots__/index.spec.js.snap rename to src/submit-bar/test/__snapshots__/index.spec.ts.snap diff --git a/src/submit-bar/test/index.spec.js b/src/submit-bar/test/index.spec.ts similarity index 95% rename from src/submit-bar/test/index.spec.js rename to src/submit-bar/test/index.spec.ts index 0a693a77b..ea7c2af64 100644 --- a/src/submit-bar/test/index.spec.js +++ b/src/submit-bar/test/index.spec.ts @@ -1,5 +1,5 @@ import SubmitBar from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit submit event when submit button is clicked', () => { const wrapper = mount(SubmitBar); @@ -78,9 +78,7 @@ test('should adjust text align when using text-align prop', () => { textAlign: 'left', }, }); - expect(wrapper.find('.van-submit-bar__text').element.style.textAlign).toEqual( - 'left' - ); + expect(wrapper.find('.van-submit-bar__text').style.textAlign).toEqual('left'); }); test('should allow to disable safe-area-inset-bottom prop', () => { diff --git a/src/switch/test/__snapshots__/index.spec.js.snap b/src/switch/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/switch/test/__snapshots__/index.spec.js.snap rename to src/switch/test/__snapshots__/index.spec.ts.snap diff --git a/src/switch/test/index.spec.js b/src/switch/test/index.spec.ts similarity index 92% rename from src/switch/test/index.spec.js rename to src/switch/test/index.spec.ts index 3ad1dd35b..81860ee01 100644 --- a/src/switch/test/index.spec.js +++ b/src/switch/test/index.spec.ts @@ -1,5 +1,5 @@ import Switch from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit update:modelValue event when click the switch button', async () => { const wrapper = mount(Switch); @@ -47,7 +47,7 @@ test('should change active color when using active-color prop', () => { }, }); - expect(wrapper.element.style.backgroundColor).toEqual('black'); + expect(wrapper.style.backgroundColor).toEqual('black'); }); test('should change inactive color when using inactive-color prop', () => { @@ -57,7 +57,7 @@ test('should change inactive color when using inactive-color prop', () => { }, }); - expect(wrapper.element.style.backgroundColor).toEqual('black'); + expect(wrapper.style.backgroundColor).toEqual('black'); }); test('should apply active color to loading icon', () => { @@ -92,7 +92,7 @@ test('should change size when using size prop', () => { }, }); - expect(wrapper.element.style.fontSize).toEqual('20px'); + expect(wrapper.style.fontSize).toEqual('20px'); }); test('should allow to custom active-value and inactive-value', () => { diff --git a/src/tab/test/index.legacy.js b/src/tab/test/index.legacy.js index d2e746a15..e49f8d2d2 100644 --- a/src/tab/test/index.legacy.js +++ b/src/tab/test/index.legacy.js @@ -241,7 +241,7 @@ test('title-style prop', () => { `, }); - expect(wrapper.find('.van-tab').element.style.color).toEqual('red'); + expect(wrapper.find('.van-tab').style.color).toEqual('red'); }); test('dot prop', () => { diff --git a/src/tabbar/test/__snapshots__/index.spec.js.snap b/src/tabbar/test/__snapshots__/index.spec.tsx.snap similarity index 100% rename from src/tabbar/test/__snapshots__/index.spec.js.snap rename to src/tabbar/test/__snapshots__/index.spec.tsx.snap diff --git a/src/tabbar/test/index.spec.js b/src/tabbar/test/index.spec.tsx similarity index 99% rename from src/tabbar/test/index.spec.js rename to src/tabbar/test/index.spec.tsx index 2a8e58bc1..3c5426d5d 100644 --- a/src/tabbar/test/index.spec.js +++ b/src/tabbar/test/index.spec.tsx @@ -11,7 +11,7 @@ function getMockRouter() { name: '/', path: '/', }); - const push = (val) => { + const push = (val: unknown) => { if (typeof val === 'string') { $route.name = val; $route.path = val; diff --git a/src/tag/test/__snapshots__/index.spec.js.snap b/src/tag/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/tag/test/__snapshots__/index.spec.js.snap rename to src/tag/test/__snapshots__/index.spec.ts.snap diff --git a/src/tag/test/index.spec.js b/src/tag/test/index.spec.ts similarity index 95% rename from src/tag/test/index.spec.js rename to src/tag/test/index.spec.ts index 7028e177c..ad05a00d0 100644 --- a/src/tag/test/index.spec.js +++ b/src/tag/test/index.spec.ts @@ -1,5 +1,5 @@ import Tag from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('should emit close event when clicking the close icon', () => { const wrapper = mount(Tag, { diff --git a/src/toast/test/index.spec.js b/src/toast/test/index.spec.js index ab96603e6..0beff74c7 100644 --- a/src/toast/test/index.spec.js +++ b/src/toast/test/index.spec.js @@ -1,6 +1,6 @@ import Toast from '../Toast'; -import { mount } from '@vue/test-utils'; -import { later } from '../../../test'; +import { mount , later } from '../../../test'; + test('should change overlay style after using overlay-style prop', async () => { const wrapper = mount(Toast, { @@ -13,7 +13,7 @@ test('should change overlay style after using overlay-style prop', async () => { }); await later(); - expect(wrapper.find('.van-overlay').element.style.background).toEqual('red'); + expect(wrapper.find('.van-overlay').style.background).toEqual('red'); }); test('should close Toast when using closeOnClick prop and clicked', () => { diff --git a/src/tree-select/test/index.legacy.js b/src/tree-select/test/index.legacy.js index d2947c44e..cbd80a7f4 100644 --- a/src/tree-select/test/index.legacy.js +++ b/src/tree-select/test/index.legacy.js @@ -1,5 +1,5 @@ import TreeSelect from '..'; -import { mount } from '@vue/test-utils'; +import { mount } from '../../../test'; test('empty list', () => { expect(mount(TreeSelect)).toMatchSnapshot(); diff --git a/test/event.ts b/test/event.ts index a193dd03a..ae8b7f94a 100644 --- a/test/event.ts +++ b/test/event.ts @@ -1,5 +1,5 @@ import { ComponentPublicInstance, nextTick } from 'vue'; -import { VueWrapper } from '@vue/test-utils'; +import { VueWrapper, DOMWrapper } from '@vue/test-utils'; function getTouch(el: Element | Window, x: number, y: number) { return { @@ -18,7 +18,11 @@ function getTouch(el: Element | Window, x: number, y: number) { // Trigger pointer/touch event export function trigger( - wrapper: VueWrapper | HTMLElement | Window, + wrapper: + | VueWrapper> + | DOMWrapper + | Element + | Window, eventName: string, x = 0, y = 0, @@ -49,7 +53,10 @@ export function trigger( // simulate drag gesture export function triggerDrag( - el: VueWrapper | HTMLElement, + el: + | VueWrapper> + | DOMWrapper + | HTMLElement, x = 0, y = 0 ) {