@@ -116,7 +116,7 @@ describe('Subscription', () => {
116116 } ) ;
117117
118118 describe ( 'unsubscribe()' , ( ) => {
119- it ( 'Should unsubscribe from all subscriptions, when some of them throw' , ( done ) => {
119+ it ( 'should unsubscribe from all subscriptions, when some of them throw' , ( done ) => {
120120 const tearDowns : number [ ] = [ ] ;
121121
122122 const source1 = new Observable ( ( ) => {
@@ -149,7 +149,7 @@ describe('Subscription', () => {
149149 } ) ;
150150 } ) ;
151151
152- it ( 'Should unsubscribe from all subscriptions, when adding a bad custom subscription to a subscription' , ( done ) => {
152+ it ( 'should unsubscribe from all subscriptions, when adding a bad custom subscription to a subscription' , ( done ) => {
153153 const tearDowns : number [ ] = [ ] ;
154154
155155 const sub = new Subscription ( ) ;
@@ -189,7 +189,7 @@ describe('Subscription', () => {
189189 } ) ;
190190 } ) ;
191191
192- it ( 'Should have idempotent unsubscription' , ( ) => {
192+ it ( 'should have idempotent unsubscription' , ( ) => {
193193 let count = 0 ;
194194 const subscription = new Subscription ( ( ) => ++ count ) ;
195195 expect ( count ) . to . equal ( 0 ) ;
@@ -200,5 +200,28 @@ describe('Subscription', () => {
200200 subscription . unsubscribe ( ) ;
201201 expect ( count ) . to . equal ( 1 ) ;
202202 } ) ;
203+
204+ it ( 'should unsubscribe from all parents' , ( ) => {
205+ // https://github.com/ReactiveX/rxjs/issues/6351
206+ const a = new Subscription ( ( ) => { /* noop */ } ) ;
207+ const b = new Subscription ( ( ) => { /* noop */ } ) ;
208+ const c = new Subscription ( ( ) => { /* noop */ } ) ;
209+ const d = new Subscription ( ( ) => { /* noop */ } ) ;
210+ a . add ( d ) ;
211+ b . add ( d ) ;
212+ c . add ( d ) ;
213+ // When d is added to the subscriptions, it's added as a teardown. The
214+ // length is 1 because the teardowns passed to the ctors are stored in a
215+ // separate property.
216+ expect ( ( a as any ) . _teardowns ) . to . have . length ( 1 ) ;
217+ expect ( ( b as any ) . _teardowns ) . to . have . length ( 1 ) ;
218+ expect ( ( c as any ) . _teardowns ) . to . have . length ( 1 ) ;
219+ d . unsubscribe ( ) ;
220+ // When d is unsubscribed, it should remove itself from each of its
221+ // parents.
222+ expect ( ( a as any ) . _teardowns ) . to . have . length ( 0 ) ;
223+ expect ( ( b as any ) . _teardowns ) . to . have . length ( 0 ) ;
224+ expect ( ( c as any ) . _teardowns ) . to . have . length ( 0 ) ;
225+ } ) ;
203226 } ) ;
204227} ) ;
0 commit comments