@@ -8,6 +8,22 @@ import { processTimeoutOptions } from './tester-utils'
88
99const kLocator = Symbol . for ( '$$vitest:locator' )
1010
11+ // processTimeoutOptions calculates the remaining task time and uses it as the poll timeout
12+ // when actionTimeout is not configured (e.g. webdriverio). This would override the
13+ // configured expect.poll.timeout, making expect.element hang until the global test timeout
14+ // instead of the configured poll timeout. Inject the configured poll timeout first so
15+ // processTimeoutOptions sees it as user-provided and returns early.
16+ function resolvePollOptions ( options : ExpectPollOptions | undefined ) : ExpectPollOptions | undefined {
17+ if ( options ?. timeout != null ) {
18+ return processTimeoutOptions ( options )
19+ }
20+ const configuredPollTimeout = getWorkerState ( ) . config . expect ?. poll ?. timeout
21+ if ( configuredPollTimeout != null ) {
22+ return processTimeoutOptions ( { ...options , timeout : configuredPollTimeout } as ExpectPollOptions )
23+ }
24+ return processTimeoutOptions ( options )
25+ }
26+
1127function element < T extends HTMLElement | SVGElement | null | Locator > ( elementOrLocator : T , options ?: ExpectPollOptions ) : PromisifyDomAssertion < HTMLElement | SVGElement | null > {
1228 if ( elementOrLocator != null && ! ( elementOrLocator instanceof HTMLElement ) && ! ( elementOrLocator instanceof SVGElement ) && ! ( kLocator in elementOrLocator ) ) {
1329 throw new Error ( `Invalid element or locator: ${ elementOrLocator } . Expected an instance of HTMLElement, SVGElement or Locator, received ${ getType ( elementOrLocator ) } ` )
@@ -51,7 +67,7 @@ function element<T extends HTMLElement | SVGElement | null | Locator>(elementOrL
5167 }
5268
5369 return result
54- } , processTimeoutOptions ( options ) )
70+ } , resolvePollOptions ( options ) )
5571
5672 chai . util . flag ( expectElement , '_poll.element' , true )
5773
0 commit comments