license import { interval , Observable , of } from 'rxjs' ; import { take , takeLast , takeUntil , takeWhile } from 'rxjs/operators' ; import { asyncTest } from '../test-util' ; describe ( 'Observable.take' , ( ) => { let log ; let observable1 ; let defaultTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ; beforeEach ( ( ) => { log = [ ] ; jasmine . DEFAULT_TIMEOUT_INTERVAL = 10000 ; } ) ; afterEach ( ( ) => { jasmine . DEFAULT_TIMEOUT_INTERVAL = defaultTimeout ; } ) ; it ( 'take func callback should run in the correct zone' , ( ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return of ( 1 , 2 , 3 ) . pipe ( take ( 1 ) ) ; } ) ; subscriptionZone . run ( ( ) => { observable1 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } , ( err ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 1 , 'completed' ] ) ; } ) ; } ) ; } ) ; it ( 'takeLast func callback should run in the correct zone' , ( ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return of ( 1 , 2 , 3 ) . pipe ( takeLast ( 1 ) ) ; } ) ; subscriptionZone . run ( ( ) => { observable1 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } , ( err ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 3 , 'completed' ] ) ; } ) ; } ) ; } ) ; xit ( 'takeUntil 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 interval ( 10 ) . pipe ( takeUntil ( interval ( 25 ) ) ) ; } ) ; subscriptionZone . run ( ( ) => { observable1 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } , ( err ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 0 , 1 , 'completed' ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; it ( 'takeWhile func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const takeZone1 = Zone . current . fork ( { name : 'Take Zone1' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return interval ( 10 ) ; } ) ; observable1 = takeZone1 . run ( ( ) => { return observable1 . pipe ( takeWhile ( ( val ) => { expect ( Zone . current . name ) . toEqual ( takeZone1 . name ) ; return val < 2 ; } ) ) ; } ) ; subscriptionZone . run ( ( ) => { observable1 . subscribe ( ( result ) => { log . push ( result ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; } , ( err ) => { fail ( 'should not call error' ) ; } , ( ) => { log . push ( 'completed' ) ; expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 0 , 1 , 'completed' ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; } ) ;