mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [switch] fix type error (#9171)
* fix(components): [switch] fix type error * fix(components): [switch] fix type error
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -259,5 +259,9 @@ defineExpose({
|
||||
* @description manual focus to the switch component
|
||||
**/
|
||||
focus,
|
||||
/**
|
||||
* @description whether Switch is checked
|
||||
*/
|
||||
checked,
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user