license import { interval , Observable , race } from 'rxjs' ; import { mapTo } from 'rxjs/operators' ; import { asyncTest } from '../test-util' ; describe ( 'Observable.race' , ( ) => { let log ; let observable1 ; beforeEach ( ( ) => { log = [ ] ; } ) ; it ( 'race func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return race ( interval ( 10 ) . pipe ( mapTo ( 'a' ) ) , interval ( 15 ) . pipe ( mapTo ( 'b' ) ) ) ; } ) ; subscriptionZone . run ( ( ) => { const subscriber = observable1 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; subscriber . complete ( ) ; } , ( err ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 'a' , 'completed' ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; } ) ;