Skip to content

Commit

Permalink
test(catch): add test for unsubscription chains
Browse files Browse the repository at this point in the history
Add test that catch() should not break unsubscription chain.

For issue #875.
  • Loading branch information
staltz authored and benlesh committed Dec 4, 2015
1 parent fe0eb37 commit c9c535c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions spec/operators/catch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Observable.prototype.catch()', function () {
});

it('should catch error and replace it with a cold Observable', function () {
var e1 = hot('--a--b--#----| ');
var e1 = hot('--a--b--# ');
var e1subs = '^ ! ';
var e2 = cold( '1-2-3-4-5-|');
var e2subs = ' ^ !';
Expand All @@ -39,9 +39,9 @@ describe('Observable.prototype.catch()', function () {

it('should allow unsubscribing explicitly and early', function () {
var e1 = hot('--1-2-3-4-5-6---#');
var unsub = ' ! ';
var e1subs = '^ ! ';
var expected = '--1-2-3- ';
var unsub = ' ! ';

var result = e1.catch(function () {
return Observable.of('X', 'Y', 'Z');
Expand All @@ -51,6 +51,23 @@ describe('Observable.prototype.catch()', function () {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should not break unsubscription chain when unsubscribed explicitly', function () {
var e1 = hot('--1-2-3-4-5-6---#');
var e1subs = '^ ! ';
var expected = '--1-2-3- ';
var unsub = ' ! ';

var result = e1
.mergeMap(function (x) { return Observable.of(x); })
.catch(function () {
return Observable.of('X', 'Y', 'Z');
})
.mergeMap(function (x) { return Observable.of(x); });

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should catch error and replace it with a hot Observable', function () {
var e1 = hot('--a--b--#----| ');
var e1subs = '^ ! ';
Expand Down

0 comments on commit c9c535c

Please sign in to comment.