@@ -14,6 +14,7 @@ import {
1414 fireEvent as dtlFireEvent ,
1515 screen as dtlScreen ,
1616 queries as dtlQueries ,
17+ waitForOptions ,
1718} from '@testing-library/dom' ;
1819import { RenderComponentOptions , RenderDirectiveOptions , RenderResult } from './models' ;
1920import { createSelectOptions , createType , tab } from './user-events' ;
@@ -147,26 +148,13 @@ export async function render<SutType, WrapperType = SutType>(
147148 return result ;
148149 } ;
149150
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 > {
159152 return waitForWrapper ( detectChanges , callback , options ) ;
160153 }
161154
162155 function componentWaitForElementToBeRemoved < T > (
163156 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 } ,
170158 ) : Promise < T > {
171159 return waitForElementToBeRemovedWrapper ( detectChanges , callback , options ) ;
172160 }
@@ -255,13 +243,8 @@ function addAutoImports({ imports, routes }: Pick<RenderComponentOptions<any>, '
255243 */
256244async function waitForWrapper < T > (
257245 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 ,
265248) : Promise < T > {
266249 return await dtlWaitFor ( ( ) => {
267250 detectChanges ( ) ;
@@ -275,12 +258,7 @@ async function waitForWrapper<T>(
275258async function waitForElementToBeRemovedWrapper < T > (
276259 detectChanges : ( ) => void ,
277260 callback : ( ( ) => T ) | T ,
278- options ?: {
279- container ?: HTMLElement ;
280- timeout ?: number ;
281- interval ?: number ;
282- mutationObserverOptions ?: MutationObserverInit ;
283- } ,
261+ options ?: waitForOptions ,
284262) : Promise < T > {
285263 let cb ;
286264 if ( typeof callback !== 'function' ) {
@@ -328,12 +306,12 @@ function replaceFindWithFindAndDetectChanges<T>(container: HTMLElement, original
328306 ( newQueries , key ) => {
329307 if ( key . startsWith ( 'find' ) ) {
330308 const getByQuery = dtlQueries [ key . replace ( 'find' , 'get' ) ] ;
331- newQueries [ key ] = async ( text , options , waitForOptions ) => {
309+ newQueries [ key ] = async ( text , options , waitOptions ) => {
332310 // original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
333311 const result = await waitForWrapper (
334312 detectChangesForMountedFixtures ,
335313 ( ) => getByQuery ( container , text , options ) ,
336- waitForOptions ,
314+ waitOptions ,
337315 ) ;
338316 return result ;
339317 } ;
@@ -377,30 +355,14 @@ const screen = replaceFindWithFindAndDetectChanges(document.body, dtlScreen);
377355/**
378356 * Re-export waitFor with patched waitFor
379357 */
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 > {
389359 return waitForWrapper ( detectChangesForMountedFixtures , callback , options ) ;
390360}
391361
392362/**
393363 * Re-export waitForElementToBeRemoved with patched waitForElementToBeRemoved
394364 */
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 > {
404366 return waitForElementToBeRemovedWrapper ( detectChangesForMountedFixtures , callback , options ) ;
405367}
406368
0 commit comments