@@ -14,6 +14,7 @@ import {
14
14
fireEvent as dtlFireEvent ,
15
15
screen as dtlScreen ,
16
16
queries as dtlQueries ,
17
+ waitForOptions ,
17
18
} from '@testing-library/dom' ;
18
19
import { RenderComponentOptions , RenderDirectiveOptions , RenderResult } from './models' ;
19
20
import { createSelectOptions , createType , tab } from './user-events' ;
@@ -147,26 +148,13 @@ export async function render<SutType, WrapperType = SutType>(
147
148
return result ;
148
149
} ;
149
150
150
- function componentWaitFor < T > (
151
- callback ,
152
- options : {
153
- container ?: HTMLElement ;
154
- timeout ?: number ;
155
- interval ?: number ;
156
- mutationObserverOptions ?: MutationObserverInit ;
157
- } = { container : fixture . nativeElement } ,
158
- ) : Promise < T > {
151
+ function componentWaitFor < T > ( callback , options : waitForOptions = { container : fixture . nativeElement } ) : Promise < T > {
159
152
return waitForWrapper ( detectChanges , callback , options ) ;
160
153
}
161
154
162
155
function componentWaitForElementToBeRemoved < T > (
163
156
callback : ( ( ) => T ) | T ,
164
- options : {
165
- container ?: HTMLElement ;
166
- timeout ?: number ;
167
- interval ?: number ;
168
- mutationObserverOptions ?: MutationObserverInit ;
169
- } = { container : fixture . nativeElement } ,
157
+ options : waitForOptions = { container : fixture . nativeElement } ,
170
158
) : Promise < T > {
171
159
return waitForElementToBeRemovedWrapper ( detectChanges , callback , options ) ;
172
160
}
@@ -255,13 +243,8 @@ function addAutoImports({ imports, routes }: Pick<RenderComponentOptions<any>, '
255
243
*/
256
244
async function waitForWrapper < T > (
257
245
detectChanges : ( ) => void ,
258
- callback : ( ) => T ,
259
- options ?: {
260
- container ?: HTMLElement ;
261
- timeout ?: number ;
262
- interval ?: number ;
263
- mutationObserverOptions ?: MutationObserverInit ;
264
- } ,
246
+ callback : ( ) => T extends Promise < any > ? never : T ,
247
+ options ?: waitForOptions ,
265
248
) : Promise < T > {
266
249
return await dtlWaitFor ( ( ) => {
267
250
detectChanges ( ) ;
@@ -275,12 +258,7 @@ async function waitForWrapper<T>(
275
258
async function waitForElementToBeRemovedWrapper < T > (
276
259
detectChanges : ( ) => void ,
277
260
callback : ( ( ) => T ) | T ,
278
- options ?: {
279
- container ?: HTMLElement ;
280
- timeout ?: number ;
281
- interval ?: number ;
282
- mutationObserverOptions ?: MutationObserverInit ;
283
- } ,
261
+ options ?: waitForOptions ,
284
262
) : Promise < T > {
285
263
let cb ;
286
264
if ( typeof callback !== 'function' ) {
@@ -328,12 +306,12 @@ function replaceFindWithFindAndDetectChanges<T>(container: HTMLElement, original
328
306
( newQueries , key ) => {
329
307
if ( key . startsWith ( 'find' ) ) {
330
308
const getByQuery = dtlQueries [ key . replace ( 'find' , 'get' ) ] ;
331
- newQueries [ key ] = async ( text , options , waitForOptions ) => {
309
+ newQueries [ key ] = async ( text , options , waitOptions ) => {
332
310
// original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
333
311
const result = await waitForWrapper (
334
312
detectChangesForMountedFixtures ,
335
313
( ) => getByQuery ( container , text , options ) ,
336
- waitForOptions ,
314
+ waitOptions ,
337
315
) ;
338
316
return result ;
339
317
} ;
@@ -377,30 +355,14 @@ const screen = replaceFindWithFindAndDetectChanges(document.body, dtlScreen);
377
355
/**
378
356
* Re-export waitFor with patched waitFor
379
357
*/
380
- async function waitFor < T > (
381
- callback : ( ) => T ,
382
- options ?: {
383
- container ?: HTMLElement ;
384
- timeout ?: number ;
385
- interval ?: number ;
386
- mutationObserverOptions ?: MutationObserverInit ;
387
- } ,
388
- ) : Promise < T > {
358
+ async function waitFor < T > ( callback : ( ) => T extends Promise < any > ? never : T , options ?: waitForOptions ) : Promise < T > {
389
359
return waitForWrapper ( detectChangesForMountedFixtures , callback , options ) ;
390
360
}
391
361
392
362
/**
393
363
* Re-export waitForElementToBeRemoved with patched waitForElementToBeRemoved
394
364
*/
395
- async function waitForElementToBeRemoved < T > (
396
- callback : ( ( ) => T ) | T ,
397
- options ?: {
398
- container ?: HTMLElement ;
399
- timeout ?: number ;
400
- interval ?: number ;
401
- mutationObserverOptions ?: MutationObserverInit ;
402
- } ,
403
- ) : Promise < T > {
365
+ async function waitForElementToBeRemoved < T > ( callback : ( ( ) => T ) | T , options ?: waitForOptions ) : Promise < T > {
404
366
return waitForElementToBeRemovedWrapper ( detectChangesForMountedFixtures , callback , options ) ;
405
367
}
406
368
0 commit comments