@@ -4,7 +4,16 @@ import { By } from '@angular/platform-browser';
4
4
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
5
import { Router } from '@angular/router' ;
6
6
import { RouterTestingModule } from '@angular/router/testing' ;
7
- import { fireEvent , FireFunction , FireObject , getQueriesForElement , prettyDOM } from '@testing-library/dom' ;
7
+ import {
8
+ fireEvent ,
9
+ FireFunction ,
10
+ FireObject ,
11
+ getQueriesForElement ,
12
+ prettyDOM ,
13
+ waitForDomChange ,
14
+ waitForElement ,
15
+ waitForElementToBeRemoved ,
16
+ } from '@testing-library/dom' ;
8
17
import { RenderComponentOptions , RenderDirectiveOptions , RenderResult } from './models' ;
9
18
import { createSelectOptions , createType } from './user-events' ;
10
19
@@ -111,6 +120,45 @@ export async function render<SutType, WrapperType = SutType>(
111
120
return result ;
112
121
} ;
113
122
123
+ function componentWaitForDomChange < Result > ( options ?: {
124
+ container ?: HTMLElement ;
125
+ timeout ?: number ;
126
+ mutationObserverOptions ?: MutationObserverInit ;
127
+ } ) : Promise < Result > {
128
+ const interval = setInterval ( detectChanges , 10 ) ;
129
+ return waitForDomChange < Result > ( { container : fixture . nativeElement , ...options } ) . finally ( ( ) =>
130
+ clearInterval ( interval ) ,
131
+ ) ;
132
+ }
133
+
134
+ function componentWaitForElement < Result > (
135
+ callback : ( ) => Result ,
136
+ options ?: {
137
+ container ?: HTMLElement ;
138
+ timeout ?: number ;
139
+ mutationObserverOptions ?: MutationObserverInit ;
140
+ } ,
141
+ ) : Promise < Result > {
142
+ const interval = setInterval ( detectChanges , 10 ) ;
143
+ return waitForElement ( callback , { container : fixture . nativeElement , ...options } ) . finally ( ( ) =>
144
+ clearInterval ( interval ) ,
145
+ ) ;
146
+ }
147
+
148
+ function componentWaitForElementToBeRemoved < Result > (
149
+ callback : ( ) => Result ,
150
+ options ?: {
151
+ container ?: HTMLElement ;
152
+ timeout ?: number ;
153
+ mutationObserverOptions ?: MutationObserverInit ;
154
+ } ,
155
+ ) : Promise < Result > {
156
+ const interval = setInterval ( detectChanges , 10 ) ;
157
+ return waitForElementToBeRemoved ( callback , { container : fixture . nativeElement , ...options } ) . finally ( ( ) =>
158
+ clearInterval ( interval ) ,
159
+ ) ;
160
+ }
161
+
114
162
return {
115
163
fixture,
116
164
detectChanges,
@@ -121,6 +169,9 @@ export async function render<SutType, WrapperType = SutType>(
121
169
debug : ( element = fixture . nativeElement ) => console . log ( prettyDOM ( element ) ) ,
122
170
type : createType ( eventsWithDetectChanges ) ,
123
171
selectOptions : createSelectOptions ( eventsWithDetectChanges ) ,
172
+ waitForDomChange : componentWaitForDomChange ,
173
+ waitForElement : componentWaitForElement ,
174
+ waitForElementToBeRemoved : componentWaitForElementToBeRemoved ,
124
175
...getQueriesForElement ( fixture . nativeElement , queries ) ,
125
176
...eventsWithDetectChanges ,
126
177
} ;
0 commit comments