license import '../zone-spec/fake-async-test' ; Zone . __load_patch ( 'fakeasync' , ( global , Zone , api ) => { const FakeAsyncTestZoneSpec = Zone && ( Zone as any ) [ 'FakeAsyncTestZoneSpec' ] ; type ProxyZoneSpec = { setDelegate ( delegateSpec ) : void ; getDelegate ( ) : ZoneSpec ; resetDelegate ( ) : void ; } ; const ProxyZoneSpec = Zone && ( Zone as any ) [ 'ProxyZoneSpec' ] ; let _fakeAsyncTestZoneSpec = null ; experimental function resetFakeAsyncZone ( ) { if ( _fakeAsyncTestZoneSpec ) { _fakeAsyncTestZoneSpec . unlockDatePatch ( ) ; } _fakeAsyncTestZoneSpec = null ; ProxyZoneSpec && ProxyZoneSpec . assertPresent ( ) . resetDelegate ( ) ; } param fn returns experimental function fakeAsync ( fn ) { return function ( ... args ) { const proxyZoneSpec = ProxyZoneSpec . assertPresent ( ) ; if ( Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ) { throw new Error ( 'fakeAsync() calls can not be nested' ) ; } try { if ( ! _fakeAsyncTestZoneSpec ) { if ( proxyZoneSpec . getDelegate ( ) instanceof FakeAsyncTestZoneSpec ) { throw new Error ( 'fakeAsync() calls can not be nested' ) ; } _fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec ( ) ; } let res ; const lastProxyZoneSpec = proxyZoneSpec . getDelegate ( ) ; proxyZoneSpec . setDelegate ( _fakeAsyncTestZoneSpec ) ; _fakeAsyncTestZoneSpec . lockDatePatch ( ) ; try { res = fn . apply ( this , args ) ; flushMicrotasks ( ) ; } finally { proxyZoneSpec . setDelegate ( lastProxyZoneSpec ) ; } if ( _fakeAsyncTestZoneSpec . pendingPeriodicTimers . length > 0 ) { throw new Error ( `${ _fakeAsyncTestZoneSpec . pendingPeriodicTimers . length } ` + `periodic timer(s) still in the queue.` ) ; } if ( _fakeAsyncTestZoneSpec . pendingTimers . length > 0 ) { throw new Error ( `${ _fakeAsyncTestZoneSpec . pendingTimers . length } timer(s) still in the queue.` ) ; } return res ; } finally { resetFakeAsyncZone ( ) ; } } ; } function _getFakeAsyncZoneSpec ( ) { if ( _fakeAsyncTestZoneSpec == null ) { _fakeAsyncTestZoneSpec = Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ; if ( _fakeAsyncTestZoneSpec == null ) { throw new Error ( 'The code should be running in the fakeAsync zone to call this function' ) ; } } return _fakeAsyncTestZoneSpec ; } experimental function tick ( millis = 0 ) { _getFakeAsyncZoneSpec ( ) . tick ( millis ) ; } param maxTurns returns experimental function flush ( maxTurns ? ) { return _getFakeAsyncZoneSpec ( ) . flush ( maxTurns ) ; } experimental function discardPeriodicTasks ( ) { const zoneSpec = _getFakeAsyncZoneSpec ( ) ; const pendingTimers = zoneSpec . pendingPeriodicTimers ; zoneSpec . pendingPeriodicTimers . length = 0 ; } experimental function flushMicrotasks ( ) { _getFakeAsyncZoneSpec ( ) . flushMicrotasks ( ) ; } ( Zone as any ) [ api . symbol ( 'fakeAsyncTest' ) ] = { resetFakeAsyncZone , flushMicrotasks , discardPeriodicTasks , tick , flush , fakeAsync } ; } ) ;