diff --git a/examples/sites/demos/pc/app/switch/webdoc/switch.js b/examples/sites/demos/pc/app/switch/webdoc/switch.js
index 58a7785cc..0bac215ff 100644
--- a/examples/sites/demos/pc/app/switch/webdoc/switch.js
+++ b/examples/sites/demos/pc/app/switch/webdoc/switch.js
@@ -153,7 +153,7 @@ export default {
'type': '(value: boolean | string | number) => void',
'defaultValue': '--',
'desc': {
- 'zh-CN': 'switch 发生变化的回调函数',
+ 'zh-CN': 'switch 状态发生变化时的回调函数',
'en-US': 'Callback function for switch changes'
},
'demoId': 'event-change'
diff --git a/packages/vue/src/switch/__tests__/switch.test.tsx b/packages/vue/src/switch/__tests__/switch.test.tsx
index f3d97e564..3b4f73704 100644
--- a/packages/vue/src/switch/__tests__/switch.test.tsx
+++ b/packages/vue/src/switch/__tests__/switch.test.tsx
@@ -1,7 +1,7 @@
import { mountPcMode } from '@opentiny-internal/vue-test-utils'
import { describe, expect, test, vi } from 'vitest'
import Switch from '@opentiny/vue-switch'
-import { nextTick } from 'vue'
+import { nextTick, ref } from 'vue'
let value = false
@@ -21,8 +21,7 @@ describe('PC Mode', () => {
v-slots={{
open: () => 是,
close: () => 否
- }}
- >
+ }}>
))
expect(wrapper.find('.no').exists()).toBe(true)
})
@@ -35,7 +34,35 @@ describe('PC Mode', () => {
expect(handleClick).toHaveBeenCalled()
})
- test.todo('base 基本用法')
- test.todo('true-value & false-value 自定义开关取值')
- test.todo('disable 禁用状态')
+ test('base 基本用法', async () => {
+ const switchValue = ref(false)
+ const wrapper = mount(() => )
+ expect(wrapper.find('.tiny-switch').exists()).toBe(true)
+ switchValue.value = true
+ await nextTick()
+ expect(wrapper.find('.tiny-switch.tiny-switch-checked').exists()).toBe(true)
+ })
+
+ test('tabindex', () => {
+ const wrapper = mount(() => )
+ expect(wrapper.find('.tiny-switch').attributes().tabindex).toBe('0')
+ })
+
+ test('true-value & false-value 自定义开关取值', async () => {
+ const switchValue = ref('yes')
+ const wrapper = mount(() => )
+ expect(wrapper.find('.tiny-switch.tiny-switch-checked').exists()).toBe(true)
+ await wrapper.find('.tiny-switch').trigger('click')
+ await nextTick()
+ expect(switchValue.value).toBe('no')
+ })
+
+ test('disable 禁用状态', async () => {
+ const value = ref(true)
+ const wrapper = mount(() => )
+
+ expect(value.value).toEqual(true)
+ await wrapper.find('.tiny-switch').trigger('click')
+ expect(value.value).toEqual(true)
+ })
})