@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {Observable, interval, merge, of , range} from 'rxjs';
|
||||
import {interval, merge, Observable, of, range} from 'rxjs';
|
||||
import {expand, map, mergeAll, mergeMap, mergeMapTo, switchAll, switchMap, switchMapTo, take} from 'rxjs/operators';
|
||||
|
||||
import {asyncTest, ifEnvSupports} from '../test-util';
|
||||
@ -22,20 +22,24 @@ describe('Observable.merge', () => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
});
|
||||
|
||||
afterEach(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = defaultTimeout; });
|
||||
afterEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = defaultTimeout;
|
||||
});
|
||||
|
||||
it('expand func callback should run in the correct zone', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const expandZone1: Zone = Zone.current.fork({name: 'Expand Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
const error = new Error('test');
|
||||
observable1 = constructorZone1.run(() => { return of (2); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return of(2);
|
||||
});
|
||||
|
||||
observable1 = expandZone1.run(() => {
|
||||
return observable1.pipe(
|
||||
expand((val: any) => {
|
||||
expect(Zone.current.name).toEqual(expandZone1.name);
|
||||
return of (1 + val);
|
||||
return of(1 + val);
|
||||
}),
|
||||
take(2));
|
||||
});
|
||||
@ -46,7 +50,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -59,8 +65,9 @@ describe('Observable.merge', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
const error = new Error('test');
|
||||
observable1 = constructorZone1.run(
|
||||
() => { return merge(interval(10).pipe(take(2)), interval(15).pipe(take(1))); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return merge(interval(10).pipe(take(2)), interval(15).pipe(take(1)));
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -68,7 +75,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -82,8 +91,13 @@ describe('Observable.merge', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
const error = new Error('test');
|
||||
observable1 = constructorZone1.run(
|
||||
() => { return of (1, 2).pipe(map((v: any) => { return of (v + 1); }), mergeAll()); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return of(1, 2).pipe(
|
||||
map((v: any) => {
|
||||
return of(v + 1);
|
||||
}),
|
||||
mergeAll());
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -91,7 +105,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -105,8 +121,11 @@ describe('Observable.merge', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
const error = new Error('test');
|
||||
observable1 = constructorZone1.run(
|
||||
() => { return of (1, 2).pipe(mergeMap((v: any) => { return of (v + 1); })); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return of(1, 2).pipe(mergeMap((v: any) => {
|
||||
return of(v + 1);
|
||||
}));
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -114,7 +133,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -127,7 +148,9 @@ describe('Observable.merge', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
const error = new Error('test');
|
||||
observable1 = constructorZone1.run(() => { return of (1, 2).pipe(mergeMapTo(of (10))); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return of(1, 2).pipe(mergeMapTo(of(10)));
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -135,7 +158,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -148,7 +173,11 @@ describe('Observable.merge', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return range(0, 3).pipe(map(function(x: any) { return range(x, 3); }), switchAll());
|
||||
return range(0, 3).pipe(
|
||||
map(function(x: any) {
|
||||
return range(x, 3);
|
||||
}),
|
||||
switchAll());
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
@ -157,7 +186,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -169,8 +200,11 @@ describe('Observable.merge', () => {
|
||||
it('switchMap func callback should run in the correct zone', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
observable1 = constructorZone1.run(
|
||||
() => { return range(0, 3).pipe(switchMap(function(x: any) { return range(x, 3); })); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return range(0, 3).pipe(switchMap(function(x: any) {
|
||||
return range(x, 3);
|
||||
}));
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -178,7 +212,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
@ -190,7 +226,9 @@ describe('Observable.merge', () => {
|
||||
it('switchMapTo func callback should run in the correct zone', () => {
|
||||
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
||||
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
||||
observable1 = constructorZone1.run(() => { return range(0, 3).pipe(switchMapTo('a')); });
|
||||
observable1 = constructorZone1.run(() => {
|
||||
return range(0, 3).pipe(switchMapTo('a'));
|
||||
});
|
||||
|
||||
subscriptionZone.run(() => {
|
||||
observable1.subscribe(
|
||||
@ -198,7 +236,9 @@ describe('Observable.merge', () => {
|
||||
log.push(result);
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
},
|
||||
(err: any) => { fail('should not call error'); },
|
||||
(err: any) => {
|
||||
fail('should not call error');
|
||||
},
|
||||
() => {
|
||||
log.push('completed');
|
||||
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
||||
|
Reference in New Issue
Block a user