File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
packages/vitest/src/integrations/chai Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import type { Test } from '@vitest/runner'
33import { chai } from '@vitest/expect'
44import { delay , getSafeTimers } from '@vitest/utils/timers'
55import { getWorkerState } from '../../runtime/utils'
6+ import { vi } from '../vi'
67
78// these matchers are not supported because they don't make sense with poll
89const unsupported = [
@@ -123,6 +124,9 @@ export function createExpectPoll(expect: ExpectStatic): ExpectStatic['poll'] {
123124 }
124125
125126 await delay ( interval , setTimeout )
127+ if ( vi . isFakeTimers ( ) ) {
128+ vi . advanceTimersByTime ( interval )
129+ }
126130 }
127131 }
128132 }
Original file line number Diff line number Diff line change @@ -66,6 +66,21 @@ test('fake timers don\'t break it', async () => {
6666 expect ( diff >= 100 ) . toBe ( true )
6767} )
6868
69+ test ( 'fake timers are advanced on each poll interval' , async ( { onTestFinished } ) => {
70+ vi . useFakeTimers ( )
71+ onTestFinished ( ( ) => {
72+ vi . useRealTimers ( )
73+ } )
74+
75+ let didAdvance = false
76+
77+ setTimeout ( ( ) => {
78+ didAdvance = true
79+ } , 50 )
80+
81+ await expect . poll ( ( ) => didAdvance , { interval : 100 } ) . toBe ( true )
82+ } )
83+
6984test ( 'custom matcher works correctly' , async ( ) => {
7085 const fn = vi . fn ( )
7186 let idx = 0
You can’t perform that action at this time.
0 commit comments