@@ -55,6 +55,9 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
55
55
checkRemainingMacrotasks ?: boolean
56
56
} = { checkNested : true , checkRemainingMacrotasks : true } ) : ( ...args : any [ ] ) => any {
57
57
// Not using an arrow function to preserve context passed from call site
58
+ if ( global [ '__zone_symbol__fakeAsyncCheckRemaining' ] === false ) {
59
+ options . checkRemainingMacrotasks = false ;
60
+ }
58
61
return function ( ...args : any [ ] ) {
59
62
const proxyZoneSpec = ProxyZoneSpec . assertPresent ( ) ;
60
63
if ( Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ) {
@@ -132,8 +135,8 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
132
135
*
133
136
* @experimental
134
137
*/
135
- function tick ( millis : number = 0 ) : void {
136
- _getFakeAsyncZoneSpec ( ) . tick ( millis ) ;
138
+ function tick ( millis : number = 0 , doTick ?: ( elapsed : number ) => void ) : void {
139
+ _getFakeAsyncZoneSpec ( ) . tick ( millis , doTick ) ;
137
140
}
138
141
139
142
/**
@@ -146,8 +149,8 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
146
149
*
147
150
* @experimental
148
151
*/
149
- function flush ( maxTurns ?: number ) : number {
150
- return _getFakeAsyncZoneSpec ( ) . flush ( maxTurns ) ;
152
+ function flush ( maxTurns ?: number , isPeriodic : boolean = false ) : number {
153
+ return _getFakeAsyncZoneSpec ( ) . flush ( maxTurns , isPeriodic ) ;
151
154
}
152
155
153
156
/**
@@ -169,6 +172,40 @@ Zone.__load_patch('fakeasync', (global: any, Zone: ZoneType, api: _ZonePrivate)
169
172
function flushMicrotasks ( ) : void {
170
173
_getFakeAsyncZoneSpec ( ) . flushMicrotasks ( ) ;
171
174
}
175
+
176
+ /**
177
+ * Clear all microtasks
178
+ *
179
+ * @experimental
180
+ */
181
+ function clearAllMacrotasks ( ) : void {
182
+ _getFakeAsyncZoneSpec ( ) . clearAllMacrotasks ( ) ;
183
+ }
184
+
185
+ /**
186
+ * flush all macroTasks and discard periodic tasks
187
+ *
188
+ * @experimental
189
+ */
190
+ function flushAndDiscardPeriodicTasks ( ) : void {
191
+ const fakeAsyncSpec = _getFakeAsyncZoneSpec ( ) ;
192
+ fakeAsyncSpec . flush ( 100 , true ) ;
193
+ discardPeriodicTasks ( ) ;
194
+ }
195
+
196
+
172
197
( Zone as any ) [ api . symbol ( 'fakeAsyncTest' ) ] =
173
- { resetFakeAsyncZone, flushMicrotasks, discardPeriodicTasks, tick, flush, fakeAsync} ;
198
+ { resetFakeAsyncZone, flushMicrotasks, discardPeriodicTasks, tick, flush, fakeAsync, clearAllMacrotasks} ;
199
+
200
+ /**
201
+ * expose those function to global
202
+ */
203
+ global [ 'resetFakeAsyncZone' ] = resetFakeAsyncZone ;
204
+ global [ 'flushMicrotasks' ] = flushMicrotasks ;
205
+ global [ 'discardPeriodicTasks' ] = discardPeriodicTasks ;
206
+ global [ 'tick' ] = tick ;
207
+ global [ 'flush' ] = flush ;
208
+ global [ 'fakeAsyncTest' ] = fakeAsync ;
209
+ global [ 'clearAllMacrotasks' ] = clearAllMacrotasks ;
210
+ global [ 'flushAndDiscardPeriodicTasks' ] = flushAndDiscardPeriodicTasks ;
174
211
} ) ;
0 commit comments