1010
1111'use strict' ;
1212declare let jest : any ;
13- ( ( _global : any ) => {
13+ Zone . __load_patch ( 'jasmine' , ( global : any , Zone : ZoneType , api : _ZonePrivate ) => {
1414 const __extends = function ( d : any , b : any ) {
1515 for ( const p in b )
1616 if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ;
@@ -25,9 +25,9 @@ declare let jest: any;
2525 // in this case, we are running inside jest not jasmine
2626 return ;
2727 }
28- if ( typeof jasmine == 'undefined' ) throw new Error ( 'Missing: jasmine.js' ) ;
29- if ( ( jasmine as any ) [ '__zone_patch__' ] )
30- throw new Error ( `'jasmine' has already been patched with 'Zone'.` ) ;
28+ if ( typeof jasmine == 'undefined' || ( jasmine as any ) [ '__zone_patch__' ] ) {
29+ return ;
30+ }
3131 ( jasmine as any ) [ '__zone_patch__' ] = true ;
3232
3333 const SyncTestZoneSpec : { new ( name : string ) : ZoneSpec } = ( Zone as any ) [ 'SyncTestZoneSpec' ] ;
@@ -44,15 +44,15 @@ declare let jest: any;
4444 const symbol = Zone . __symbol__ ;
4545
4646 // whether patch jasmine clock when in fakeAsync
47- const disablePatchingJasmineClock = _global [ symbol ( 'fakeAsyncDisablePatchingClock' ) ] === true ;
47+ const disablePatchingJasmineClock = global [ symbol ( 'fakeAsyncDisablePatchingClock' ) ] === true ;
4848 // the original variable name fakeAsyncPatchLock is not accurate, so the name will be
4949 // fakeAsyncAutoFakeAsyncWhenClockPatched and if this enablePatchingJasmineClock is false, we also
5050 // automatically disable the auto jump into fakeAsync feature
5151 const enableAutoFakeAsyncWhenClockPatched = ! disablePatchingJasmineClock &&
52- ( ( _global [ symbol ( 'fakeAsyncPatchLock' ) ] === true ) ||
53- ( _global [ symbol ( 'fakeAsyncAutoFakeAsyncWhenClockPatched' ) ] === true ) ) ;
52+ ( ( global [ symbol ( 'fakeAsyncPatchLock' ) ] === true ) ||
53+ ( global [ symbol ( 'fakeAsyncAutoFakeAsyncWhenClockPatched' ) ] === true ) ) ;
5454
55- const ignoreUnhandledRejection = _global [ symbol ( 'ignoreUnhandledRejection' ) ] === true ;
55+ const ignoreUnhandledRejection = global [ symbol ( 'ignoreUnhandledRejection' ) ] === true ;
5656
5757 if ( ! ignoreUnhandledRejection ) {
5858 const globalErrors = ( jasmine as any ) . GlobalErrors ;
@@ -226,13 +226,13 @@ declare let jest: any;
226226 } ) ( attrs . onComplete ) ;
227227 }
228228
229- const nativeSetTimeout = _global [ Zone . __symbol__ ( 'setTimeout' ) ] ;
230- const nativeClearTimeout = _global [ Zone . __symbol__ ( 'clearTimeout' ) ] ;
229+ const nativeSetTimeout = global [ Zone . __symbol__ ( 'setTimeout' ) ] ;
230+ const nativeClearTimeout = global [ Zone . __symbol__ ( 'clearTimeout' ) ] ;
231231 if ( nativeSetTimeout ) {
232232 // should run setTimeout inside jasmine outside of zone
233233 attrs . timeout = {
234- setTimeout : nativeSetTimeout ? nativeSetTimeout : _global . setTimeout ,
235- clearTimeout : nativeClearTimeout ? nativeClearTimeout : _global . clearTimeout
234+ setTimeout : nativeSetTimeout ? nativeSetTimeout : global . setTimeout ,
235+ clearTimeout : nativeClearTimeout ? nativeClearTimeout : global . clearTimeout
236236 } ;
237237 }
238238
@@ -291,6 +291,7 @@ declare let jest: any;
291291 // This is the zone which will be used for running individual tests.
292292 // It will be a proxy zone, so that the tests function can retroactively install
293293 // different zones.
294+ // Example:
294295 // - In beforeEach() do childZone = Zone.current.fork(...);
295296 // - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the
296297 // zone outside of fakeAsync it will be able to escape the fakeAsync rules.
@@ -313,4 +314,4 @@ declare let jest: any;
313314 } ;
314315 return ZoneQueueRunner ;
315316 } ) ( QueueRunner ) ;
316- } ) ( typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global ) ;
317+ } ) ;
0 commit comments