@@ -2,6 +2,7 @@ import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/mar
2
2
import { concat , defer , Observable , of , from } from 'rxjs' ;
3
3
import { exhaustMap , mergeMap , takeWhile , map } from 'rxjs/operators' ;
4
4
import { expect } from 'chai' ;
5
+ import { asInteropObservable } from '../helpers/interop-helper' ;
5
6
6
7
declare function asDiagram ( arg : string ) : Function ;
7
8
@@ -202,6 +203,39 @@ describe('exhaustMap', () => {
202
203
expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
203
204
} ) ;
204
205
206
+ it ( 'should not break unsubscription chains with interop inners when result is unsubscribed explicitly' , ( ) => {
207
+ const x = cold ( '--a--b--c--| ' ) ;
208
+ const xsubs = ' ^ ! ' ;
209
+ const y = cold ( '--d--e--f--| ' ) ;
210
+ const ysubs : string [ ] = [ ] ;
211
+ const z = cold ( '--g--h--i--| ' ) ;
212
+ const zsubs = ' ^ ! ' ;
213
+ const e1 = hot ( '---x---------y-----------------z-------------|' ) ;
214
+ const e1subs = '^ ! ' ;
215
+ const expected = '-----a--b--c---------------------g- ' ;
216
+ const unsub = ' ! ' ;
217
+
218
+ const observableLookup = { x : x , y : y , z : z } ;
219
+
220
+ // This test is the same as the previous test, but the observable is
221
+ // manipulated to make it look like an interop observable - an observable
222
+ // from a foreign library. Interop subscribers are treated differently:
223
+ // they are wrapped in a safe subscriber. This test ensures that
224
+ // unsubscriptions are chained all the way to the interop subscriber.
225
+
226
+ const result = e1 . pipe (
227
+ mergeMap ( x => of ( x ) ) ,
228
+ exhaustMap ( value => asInteropObservable ( observableLookup [ value ] ) ) ,
229
+ mergeMap ( x => of ( x ) )
230
+ ) ;
231
+
232
+ expectObservable ( result , unsub ) . toBe ( expected ) ;
233
+ expectSubscriptions ( x . subscriptions ) . toBe ( xsubs ) ;
234
+ expectSubscriptions ( y . subscriptions ) . toBe ( ysubs ) ;
235
+ expectSubscriptions ( z . subscriptions ) . toBe ( zsubs ) ;
236
+ expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
237
+ } ) ;
238
+
205
239
it ( 'should stop listening to a synchronous observable when unsubscribed' , ( ) => {
206
240
const sideEffects : number [ ] = [ ] ;
207
241
const synchronousObservable = concat (
0 commit comments