diff --git a/src/packages/__VUE/countdown/__tests__/countdown.spec.ts b/src/packages/__VUE/countdown/__tests__/countdown.spec.tsx
similarity index 54%
rename from src/packages/__VUE/countdown/__tests__/countdown.spec.ts
rename to src/packages/__VUE/countdown/__tests__/countdown.spec.tsx
index 8aac58401a..846b8c9464 100644
--- a/src/packages/__VUE/countdown/__tests__/countdown.spec.ts
+++ b/src/packages/__VUE/countdown/__tests__/countdown.spec.tsx
@@ -1,9 +1,9 @@
import { mount } from '@vue/test-utils'
-import { nextTick, toRefs, reactive } from 'vue'
+import { nextTick, ref } from 'vue'
import { Button, Countdown } from '@nutui/nutui'
import { sleep } from '@/packages/utils/unit'
-test('endTime props', async () => {
+test('Countdown: endTime props', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50
@@ -14,7 +14,7 @@ test('endTime props', async () => {
expect(wrapper.emitted('end')).toBeTruthy()
})
-test('format props', async () => {
+test('Countdown: format props', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50,
@@ -55,28 +55,19 @@ test('format props', async () => {
expect(wrapper.find('.nut-countdown__content').text() == '000毫秒').toBe(true)
})
-test('paused props', async () => {
- const wrapper = mount({
- components: {
- 'nut-countdown': Countdown,
- 'nut-button': Button
- },
- template: `
-
- {{ paused ? 'start' : 'stop' }}
- `,
- setup() {
- const state = reactive({
- endTime: Date.now() + 1 * 50,
- paused: false
- })
-
- const toggle = () => {
- state.paused = !state.paused
- }
-
- return { ...toRefs(state), toggle }
- }
+test('Countdown: paused props', async () => {
+ const paused = ref(false)
+ const endTime = ref(Date.now() + 1 * 50)
+ const toggle = () => {
+ paused.value = !paused.value
+ }
+ const wrapper = mount(() => {
+ return (
+ <>
+
+
+ >
+ )
})
const button = wrapper.find('.nut-button')
@@ -88,7 +79,7 @@ test('paused props', async () => {
expect(prevSnapShot === laterShapShot).toBeTruthy()
})
-test('should render slot correctly', async () => {
+test('Countdown: should render slot correctly', async () => {
const wrapper = mount(Countdown, {
props: {
endTime: Date.now() + 1 * 50
@@ -99,3 +90,63 @@ test('should render slot correctly', async () => {
})
expect(wrapper.text()).toEqual('slot content')
})
+
+test('Countdown: should render slot correctly', async () => {
+ const wrapper = mount(Countdown, {
+ props: {
+ endTime: Date.now() + 1 * 50
+ },
+ slots: {
+ default: () => 'slot content'
+ }
+ })
+ expect(wrapper.text()).toEqual('slot content')
+})
+
+test('Countdown: ref methods', async () => {
+ const countdownRef = ref()
+ const start = () => {
+ countdownRef.value.start()
+ }
+ const pause = () => {
+ countdownRef.value.pause()
+ }
+ const reset = () => {
+ countdownRef.value.reset()
+ }
+ const restart = vi.fn()
+ const paused = vi.fn()
+ const wrapper = mount(() => {
+ return (
+ <>
+
+
+
+
+ >
+ )
+ })
+ const countdown = wrapper.find('.nut-countdown__content')
+ expect(countdown.text()).toBe('20:00')
+
+ const btn1 = wrapper.find('.start')
+ btn1.trigger('click')
+ expect(restart).toBeCalledTimes(1)
+ expect(paused).toBeCalledTimes(0)
+
+ const btn2 = wrapper.find('.pause')
+ btn2.trigger('click')
+ expect(restart).toBeCalledTimes(1)
+ expect(paused).toBeCalledTimes(1)
+
+ const btn3 = wrapper.find('.pause')
+ btn3.trigger('click')
+ expect(countdown.text()).toBe('20:00')
+})
diff --git a/src/packages/__VUE/countdown/countdown.taro.vue b/src/packages/__VUE/countdown/countdown.taro.vue
index 4273802683..0b207b1edf 100644
--- a/src/packages/__VUE/countdown/countdown.taro.vue
+++ b/src/packages/__VUE/countdown/countdown.taro.vue
@@ -105,8 +105,8 @@ const start = () => {
const pause = () => {
cancelAnimationFrame(timer.value!)
counting.value = false
- emit('restart', restTime.value)
- emit('onRestart', restTime.value)
+ emit('paused', restTime.value)
+ emit('onPaused', restTime.value)
}
// 重置
diff --git a/src/packages/__VUE/countdown/countdown.vue b/src/packages/__VUE/countdown/countdown.vue
index 4273802683..0b207b1edf 100644
--- a/src/packages/__VUE/countdown/countdown.vue
+++ b/src/packages/__VUE/countdown/countdown.vue
@@ -105,8 +105,8 @@ const start = () => {
const pause = () => {
cancelAnimationFrame(timer.value!)
counting.value = false
- emit('restart', restTime.value)
- emit('onRestart', restTime.value)
+ emit('paused', restTime.value)
+ emit('onPaused', restTime.value)
}
// 重置