diff --git a/spec/operators/groupBy-spec.ts b/spec/operators/groupBy-spec.ts index 8dbdab6aae..0b436bc91a 100644 --- a/spec/operators/groupBy-spec.ts +++ b/spec/operators/groupBy-spec.ts @@ -340,6 +340,34 @@ describe('Observable.prototype.groupBy', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + it('should unsubscribe from the source when the outer and inner subscriptions are disposed', () => { + const values = { + a: ' foo', + b: ' FoO ', + c: 'baR ', + d: 'foO ', + e: ' Baz ', + f: ' qux ', + g: ' bar', + h: ' BAR ', + i: 'FOO ', + j: 'baz ', + k: ' bAZ ', + l: ' fOo ' + }; + const e1 = hot('-1--2--^-a-b-c-d-e-f-g-h-i-j-k-l-|', values); + const e1subs = '^ !'; + const expected = '--(a|)'; + + const source = e1 + .groupBy((val: string) => val.toLowerCase().trim()) + .take(1) + .mergeMap((group: any) => group.take(1)); + + expectObservable(source).toBe(expected, values); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); + it('should not break unsubscription chain when unsubscribed explicitly', () => { const values = { a: ' foo', diff --git a/src/operator/groupBy.ts b/src/operator/groupBy.ts index 1ac80d275a..e94517594b 100644 --- a/src/operator/groupBy.ts +++ b/src/operator/groupBy.ts @@ -163,7 +163,7 @@ class GroupBySubscriber extends Subscriber implements RefCountSubscr } unsubscribe() { - if (!this.closed && !this.attemptedToUnsubscribe) { + if (!this.closed) { this.attemptedToUnsubscribe = true; if (this.count === 0) { super.unsubscribe();