fix(components): [switch] fix type error (#9171)

* fix(components): [switch] fix type error

* fix(components): [switch] fix type error
This commit is contained in:
LIUCHAO
2022-08-18 20:31:37 +08:00
committed by GitHub
parent f4f7c13b9a
commit 80c5855f2f
2 changed files with 11 additions and 8 deletions

View File

@@ -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<string | number | boolean>(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<boolean>((resolve, reject) => {
setTimeout(() => {
loading.value = false
return asyncResult.value == 'success'

View File

@@ -259,5 +259,9 @@ defineExpose({
* @description manual focus to the switch component
**/
focus,
/**
* @description whether Switch is checked
*/
checked,
})
</script>