|
1 | 1 | import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
|
2 |
| -import { Observable, of, from } from 'rxjs'; |
3 |
| -import { exhaustMap, mergeMap } from 'rxjs/operators'; |
| 2 | +import { concat, defer, Observable, of, from } from 'rxjs'; |
| 3 | +import { exhaustMap, mergeMap, takeWhile } from 'rxjs/operators'; |
4 | 4 | import { expect } from 'chai';
|
5 | 5 |
|
6 | 6 | declare function asDiagram(arg: string): Function;
|
@@ -202,6 +202,31 @@ describe('exhaustMap', () => {
|
202 | 202 | expectSubscriptions(e1.subscriptions).toBe(e1subs);
|
203 | 203 | });
|
204 | 204 |
|
| 205 | + it('should stop listening to a synchronous observable when unsubscribed', () => { |
| 206 | + const sideEffects: number[] = []; |
| 207 | + const synchronousObservable = concat( |
| 208 | + defer(() => { |
| 209 | + sideEffects.push(1); |
| 210 | + return of(1); |
| 211 | + }), |
| 212 | + defer(() => { |
| 213 | + sideEffects.push(2); |
| 214 | + return of(2); |
| 215 | + }), |
| 216 | + defer(() => { |
| 217 | + sideEffects.push(3); |
| 218 | + return of(3); |
| 219 | + }) |
| 220 | + ); |
| 221 | + |
| 222 | + of(null).pipe( |
| 223 | + exhaustMap(() => synchronousObservable), |
| 224 | + takeWhile((x) => x != 2) // unsubscribe at the second side-effect |
| 225 | + ).subscribe(() => { /* noop */ }); |
| 226 | + |
| 227 | + expect(sideEffects).to.deep.equal([1, 2]); |
| 228 | + }); |
| 229 | + |
205 | 230 | it('should switch inner cold observables, inner never completes', () => {
|
206 | 231 | const x = cold( '--a--b--c--| ');
|
207 | 232 | const xsubs = ' ^ ! ';
|
|
0 commit comments