@@ -116,7 +116,7 @@ describe('Subscription', () => {
116
116
} ) ;
117
117
118
118
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 ) => {
120
120
const tearDowns : number [ ] = [ ] ;
121
121
122
122
const source1 = new Observable ( ( ) => {
@@ -149,7 +149,7 @@ describe('Subscription', () => {
149
149
} ) ;
150
150
} ) ;
151
151
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 ) => {
153
153
const tearDowns : number [ ] = [ ] ;
154
154
155
155
const sub = new Subscription ( ) ;
@@ -189,7 +189,7 @@ describe('Subscription', () => {
189
189
} ) ;
190
190
} ) ;
191
191
192
- it ( 'Should have idempotent unsubscription' , ( ) => {
192
+ it ( 'should have idempotent unsubscription' , ( ) => {
193
193
let count = 0 ;
194
194
const subscription = new Subscription ( ( ) => ++ count ) ;
195
195
expect ( count ) . to . equal ( 0 ) ;
@@ -200,5 +200,28 @@ describe('Subscription', () => {
200
200
subscription . unsubscribe ( ) ;
201
201
expect ( count ) . to . equal ( 1 ) ;
202
202
} ) ;
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
+ } ) ;
203
226
} ) ;
204
227
} ) ;
0 commit comments