license import { asapScheduler , of } from 'rxjs' ; import { map , observeOn } from 'rxjs/operators' ; import { asyncTest } from '../test-util' ; describe ( 'Scheduler.asap' , ( ) => { let log ; let errorCallback ; const constructorZone = Zone . root . fork ( { name : 'Constructor Zone' } ) ; beforeEach ( ( ) => { log = [ ] ; } ) ; it ( 'scheduler asap should run in correct zone' , asyncTest ( ( done ) => { let observable ; constructorZone . run ( ( ) => { observable = of ( 1 , 2 , 3 ) . pipe ( observeOn ( asapScheduler ) ) ; } ) ; const zone = Zone . current . fork ( { name : 'subscribeZone' } ) ; zone . run ( ( ) => { observable . pipe ( map ( ( value ) => { return value ; } ) ) . subscribe ( ( value ) => { expect ( Zone . current . name ) . toEqual ( zone . name ) ; if ( value === 3 ) { setTimeout ( done ) ; } } , ( err ) => { fail ( 'should not be here' ) ; } ) ; } ) ; } , Zone . root ) ) ; it ( 'scheduler asap error should run in correct zone' , asyncTest ( ( done ) => { let observable ; constructorZone . run ( ( ) => { observable = of ( 1 , 2 , 3 ) . pipe ( observeOn ( asapScheduler ) ) ; } ) ; Zone . root . run ( ( ) => { observable . pipe ( map ( ( value ) => { if ( value === 3 ) { throw new Error ( 'oops' ) ; } return value ; } ) ) . subscribe ( ( value ) => { } , ( err ) => { expect ( err . message ) . toEqual ( 'oops' ) ; expect ( Zone . current . name ) . toEqual ( '<root>' ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; } ) ;