From 80c5855f2f0be8256ecd378afe48d1865b365969 Mon Sep 17 00:00:00 2001 From: LIUCHAO <50739490+Tsong-LC@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:31:37 +0800 Subject: [PATCH] fix(components): [switch] fix type error (#9171) * fix(components): [switch] fix type error * fix(components): [switch] fix type error --- .../components/switch/__tests__/switch.test.tsx | 15 +++++++-------- packages/components/switch/src/switch.vue | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/components/switch/__tests__/switch.test.tsx b/packages/components/switch/__tests__/switch.test.tsx index 67b675eb43..270db4365f 100644 --- a/packages/components/switch/__tests__/switch.test.tsx +++ b/packages/components/switch/__tests__/switch.test.tsx @@ -1,4 +1,3 @@ -// @ts-nocheck import { markRaw, nextTick, ref } from 'vue' import { mount } from '@vue/test-utils' import { afterEach, describe, expect, test, vi } from 'vitest' @@ -109,9 +108,9 @@ describe('Switch.vue', () => { }) test('change event', async () => { - const target = ref(1) + const target = ref(1) const value = ref(true) - const handleChange = (val: boolean) => { + const handleChange = (val: string | number | boolean) => { target.value = val } const wrapper = mount(() => ( @@ -188,11 +187,11 @@ describe('Switch.vue', () => { const switchVm = switchWrapper.vm const inputEl = vm.$el.querySelector('input') - expect(switchVm.checked).toBe(true) + expect(switchVm.$.exposed?.checked.value).toBe(true) expect(switchWrapper.classes('is-checked')).toEqual(true) expect(inputEl.checked).toEqual(true) await coreWrapper.trigger('click') - expect(switchVm.checked).toBe(true) + expect(switchVm.$.exposed?.checked.value).toBe(true) expect(switchWrapper.classes('is-checked')).toEqual(true) expect(inputEl.checked).toEqual(true) }) @@ -207,11 +206,11 @@ describe('Switch.vue', () => { const switchVm = switchWrapper.vm const inputEl = vm.$el.querySelector('input') - expect(switchVm.checked).toBe(true) + expect(switchVm.$.exposed?.checked.value).toBe(true) expect(switchWrapper.classes('is-checked')).toEqual(true) expect(inputEl.checked).toEqual(true) await coreWrapper.trigger('click') - expect(switchVm.checked).toBe(true) + expect(switchVm.$.exposed?.checked.value).toBe(true) expect(switchWrapper.classes('is-checked')).toEqual(true) expect(inputEl.checked).toEqual(true) }) @@ -240,7 +239,7 @@ describe('Switch.vue', () => { const asyncResult = ref('error') const beforeChange = () => { loading.value = true - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { setTimeout(() => { loading.value = false return asyncResult.value == 'success' diff --git a/packages/components/switch/src/switch.vue b/packages/components/switch/src/switch.vue index 1de336f93f..ee58fe2417 100644 --- a/packages/components/switch/src/switch.vue +++ b/packages/components/switch/src/switch.vue @@ -259,5 +259,9 @@ defineExpose({ * @description manual focus to the switch component **/ focus, + /** + * @description whether Switch is checked + */ + checked, })