Skip to content

Commit

Permalink
test(Subscription): add test for adding errant custom subscription to…
Browse files Browse the repository at this point in the history
… unsubscribed subscription

- tries to synchronously add a custom subscription that throws when unsubscribed to a Subscription that is mid-unsubscribe and therefor
  flagged `isUnsubscribed`. It's an edge-case, but it should work.

fixes #1256
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent 4ebb88c commit 9d5a01c
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion spec/Subscription-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,47 @@ describe('Subscription', function () {
setTimeout(function () {
expect(function () {
subscription.unsubscribe();
}).toThrow();
}).toThrow(new Rx.UnsubscriptionError([new Error('oops, I am a bad unsubscribe!')]));
expect(tearDowns).toEqual([1, 2, 3]);
done();
});
});

it('should not leak when adding a bad custom subscription to a subscription', function (done) {
var tearDowns = [];

var sub = new Subscription();

var source1 = Observable.create(function (observer) {
return function () {
tearDowns.push(1);
};
});

var source2 = Observable.create(function (observer) {
return function () {
tearDowns.push(2);
sub.add({
unsubscribe: function () {
expect(sub.isUnsubscribed).toBe(true);
throw new Error('Who is your daddy, and what does he do?');
}
});
};
});

var source3 = Observable.create(function (observer) {
return function () {
tearDowns.push(3);
};
});

sub.add(Observable.merge(source1, source2, source3).subscribe());

setTimeout(function () {
expect(function () {
sub.unsubscribe();
}).toThrow(new Rx.UnsubscriptionError([new Error('Who is your daddy, and what does he do?')]));
expect(tearDowns).toEqual([1, 2, 3]);
done();
});
Expand Down

0 comments on commit 9d5a01c

Please sign in to comment.