Skip to content

Commit

Permalink
test(share): add test against breaking unsubscription chain
Browse files Browse the repository at this point in the history
Add test for share() operator, to verify that unsubscription chains are not broken when the last
subscriber unsubscribes.

For issue #875.
  • Loading branch information
staltz authored and benlesh committed Dec 8, 2015
1 parent c9cb958 commit 5db1352
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion spec/operators/share-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ describe('Observable.prototype.share()', function () {
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});

it('should not break unsubscription chain when last subscriber unsubscribes', function () {
var source = cold( '-1-2-3----4-|');
var sourceSubs = ' ^ ! ';
var shared = source
.mergeMap(function (x) { return Observable.of(x); })
.share()
.mergeMap(function (x) { return Observable.of(x); });
var subscriber1 = hot(' a| ').mergeMapTo(shared);
var unsub1 = ' ! ';
var expected1 = ' -1-2-3-- ';
var subscriber2 = hot(' b| ').mergeMapTo(shared);
var unsub2 = ' ! ';
var expected2 = ' -3---- ';

expectObservable(subscriber1, unsub1).toBe(expected1);
expectObservable(subscriber2, unsub2).toBe(expected2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});

it('should be retryable when cold source is synchronous', function () {
var source = cold('(123#)');
var shared = source.share();
Expand Down Expand Up @@ -287,4 +306,4 @@ describe('Observable.prototype.share()', function () {

expectObservable(e1.share()).toBe(expected);
});
});
});

0 comments on commit 5db1352

Please sign in to comment.