Skip to content

Commit 1bc3e63

Browse files
authored
fix: provide vi.advanceTimers to the preview provider (#9891)
1 parent 9ae316e commit 1bc3e63

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/browser/src/client/tester/context.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { StringifyOptions } from 'vitest/internal/browser'
1616
import type { IframeViewportEvent } from '../client'
1717
import type { BrowserRunnerState } from '../utils'
1818
import type { Locator as LocatorAPI } from './locators/index'
19+
import { vi } from 'vitest'
1920
import { __INTERNAL, stringify } from 'vitest/internal/browser'
2021
import { ensureAwaited, getBrowserState, getWorkerState } from '../utils'
2122
import { convertToSelector, isLocator, processTimeoutOptions, resolveUserEventWheelOptions } from './tester-utils'
@@ -142,8 +143,11 @@ export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent
142143
return userEvent
143144
}
144145

145-
function createPreviewUserEvent(userEventBase: TestingLibraryUserEvent, options: TestingLibraryOptions): UserEvent {
146-
let userEvent = userEventBase.setup(options)
146+
function createPreviewUserEvent(userEventBase: TestingLibraryUserEvent, options?: TestingLibraryOptions): UserEvent {
147+
let userEvent = userEventBase.setup({
148+
advanceTimers: delay => vi.advanceTimersByTimeAsync(delay),
149+
...options,
150+
})
147151
let clipboardData: DataTransfer | undefined
148152

149153
function toElement(element: Element | Locator) {
@@ -155,7 +159,10 @@ function createPreviewUserEvent(userEventBase: TestingLibraryUserEvent, options:
155159
return createPreviewUserEvent(userEventBase, options)
156160
},
157161
async cleanup() {
158-
userEvent = userEventBase.setup(options ?? {})
162+
userEvent = userEventBase.setup({
163+
advanceTimers: delay => vi.advanceTimersByTimeAsync(delay),
164+
...options,
165+
})
159166
},
160167
async click(element) {
161168
await userEvent.click(toElement(element))

0 commit comments

Comments
 (0)