license import { interval , merge , Observable } from 'rxjs' ; import { map , take } from 'rxjs/operators' ; import { asyncTest } from '../test-util' ; describe ( 'Observable.merge' , ( ) => { let log ; beforeEach ( ( ) => { log = [ ] ; } ) ; it ( 'merge func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const constructorZone3 = Zone . current . fork ( { name : 'Constructor Zone3' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; const observable1 = constructorZone1 . run ( ( ) => { return interval ( 8 ) . pipe ( map ( v => 'observable1' + v ) , take ( 1 ) ) ; } ) ; const observable2 = constructorZone2 . run ( ( ) => { return interval ( 10 ) . pipe ( map ( v => 'observable2' + v ) , take ( 1 ) ) ; } ) ; const observable3 = constructorZone3 . run ( ( ) => { return merge ( observable1 , observable2 ) ; } ) ; subscriptionZone . run ( ( ) => { const subscriber = observable3 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } , ( ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 'observable10' , 'observable20' , 'completed' ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; } ) ;