From b9e7801d2398b281dca69b7aa0b6ab16abc218df Mon Sep 17 00:00:00 2001 From: inottn Date: Mon, 7 Apr 2025 10:18:57 +0800 Subject: [PATCH] test(Stepper): reduce test run time (#13421) --- packages/vant/src/stepper/test/index.spec.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/vant/src/stepper/test/index.spec.ts b/packages/vant/src/stepper/test/index.spec.ts index 9bdb6e5cb..b9801acf5 100644 --- a/packages/vant/src/stepper/test/index.spec.ts +++ b/packages/vant/src/stepper/test/index.spec.ts @@ -1,6 +1,6 @@ import { nextTick } from 'vue'; import { Stepper } from '..'; -import { mount, later } from '../../../test'; +import { mount } from '../../../test'; import { LONG_PRESS_START_TIME } from '../../utils'; test('should disable buttons and input when using disabled prop', () => { @@ -113,6 +113,7 @@ test('should limit max value when using max prop', async () => { }); test('should update value after long pressing', async () => { + vi.useFakeTimers(); const wrapper = mount(Stepper, { props: { modelValue: 1, @@ -127,12 +128,14 @@ test('should update value after long pressing', async () => { expect(wrapper.emitted('update:modelValue')![0]).toEqual([2]); await plus.trigger('touchstart'); - await later(LONG_PRESS_START_TIME + 500); + await vi.advanceTimersByTimeAsync(LONG_PRESS_START_TIME + 500); await plus.trigger('touchend'); expect(wrapper.emitted('update:modelValue')).toEqual([[2], [3], [4], [5]]); + vi.useRealTimers(); }); test('should allow to disable long press', async () => { + vi.useFakeTimers(); const wrapper = mount(Stepper, { props: { longPress: false, @@ -142,10 +145,11 @@ test('should allow to disable long press', async () => { const plus = wrapper.find('.van-stepper__plus'); await plus.trigger('touchstart'); - await later(800); + await vi.advanceTimersByTimeAsync(LONG_PRESS_START_TIME + 500); await plus.trigger('touchend'); expect(wrapper.emitted('update:modelValue')).toBeFalsy(); + vi.useRealTimers(); }); test('should filter invalid value during user input', async () => {