license /**
 * Promise for async/fakeAsync zoneSpec test
 * can support async operation which not supported by zone.js
 * such as
 * it ('test jsonp in AsyncZone', async() => {
 *   new Promise(res => {
 *     jsonp(url, (data) => {
 *       // success callback
 *       res(data);
 *     });
 *   }).then((jsonpResult) => {
 *     // get jsonp result.
 *
 *     // user will expect AsyncZoneSpec wait for
 *     // then, but because jsonp is not zone aware
 *     // AsyncZone will finish before then is called.
 *   });
 * });
 */ Zone . __load_patch ( 'promisefortest' , ( global , Zone , api ) => { const symbolState = api . symbol ( 'state' ) ; const UNRESOLVED = null ; const symbolParentUnresolved = api . symbol ( 'parentUnresolved' ) ; ( Promise as any ) [ api . symbol ( 'patchPromiseForTest' ) ] = function patchPromiseForTest ( ) { let oriThen = ( Promise as any ) [ Zone . __symbol__ ( 'ZonePromiseThen' ) ] ; if ( oriThen ) { return ; } oriThen = ( Promise as any ) [ Zone . __symbol__ ( 'ZonePromiseThen' ) ] = Promise . prototype . then ; Promise . prototype . then = function ( ) { const chained = oriThen . apply ( this , arguments ) ; if ( this [ symbolState ] === UNRESOLVED ) { const asyncTestZoneSpec = Zone . current . get ( 'AsyncTestZoneSpec' ) ; if ( asyncTestZoneSpec ) { asyncTestZoneSpec . unresolvedChainedPromiseCount ++ ; chained [ symbolParentUnresolved ] = true ; } } return chained ; } ; } ; ( Promise as any ) [ api . symbol ( 'unPatchPromiseForTest' ) ] = function unpatchPromiseForTest ( ) { const oriThen = ( Promise as any ) [ Zone . __symbol__ ( 'ZonePromiseThen' ) ] ; if ( oriThen ) { Promise . prototype . then = oriThen ; ( Promise as any ) [ Zone . __symbol__ ( 'ZonePromiseThen' ) ] = undefined ; } } ; } ) ;