license import { Observable , of , Subject } from 'rxjs' ; import { mapTo , multicast , tap } from 'rxjs/operators' ; describe ( 'Observable.multicast' , ( ) => { let log ; const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const doZone1 = Zone . current . fork ( { name : 'Do Zone1' } ) ; const mapZone1 = Zone . current . fork ( { name : 'Map Zone1' } ) ; const multicastZone1 = Zone . current . fork ( { name : 'Multicast Zone1' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; let observable1 ; beforeEach ( ( ) => { log = [ ] ; } ) ; it ( 'multicast func callback should run in the correct zone' , ( ) => { observable1 = constructorZone1 . run ( ( ) => { return of ( 1 , 2 , 3 ) ; } ) ; observable1 = doZone1 . run ( ( ) => { return observable1 . pipe ( tap ( ( v ) => { expect ( Zone . current . name ) . toEqual ( doZone1 . name ) ; log . push ( 'do' + v ) ; } ) ) ; } ) ; observable1 = mapZone1 . run ( ( ) => { return observable1 . pipe ( mapTo ( 'test' ) ) ; } ) ; const multi = multicastZone1 . run ( ( ) => { return observable1 . pipe ( multicast ( ( ) => { expect ( Zone . current . name ) . toEqual ( multicastZone1 . name ) ; return new Subject ( ) ; } ) ) ; } ) ; multi . subscribe ( ( val ) => { log . push ( 'one' + val ) ; } ) ; multi . subscribe ( ( val ) => { log . push ( 'two' + val ) ; } ) ; multi . connect ( ) ; subscriptionZone . run ( ( ) => { observable1 . subscribe ( ( result ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( result ) ; } , ( ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } ) ; } ) ; expect ( log ) . toEqual ( [ 'do1' , 'onetest' , 'twotest' , 'do2' , 'onetest' , 'twotest' , 'do3' , 'onetest' , 'twotest' , 'do1' , 'test' , 'do2' , 'test' , 'do3' , 'test' , 'completed' ] ) ; } ) ; } ) ;