Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Subject): throw ObjectUnsubscribedError when unsubecribed … #1316

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions spec/Subject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ describe('Subject', function () {
subscription1.unsubscribe();

subject.complete();
subject.next(9);
subject.complete();
subject.error(new Error('err'));

subscription2.unsubscribe();

Expand Down Expand Up @@ -179,9 +176,6 @@ describe('Subject', function () {

subscription1.unsubscribe();

subject.error(new Error('err'));
subject.next(9);
subject.complete();
subject.error(new Error('err'));

subscription2.unsubscribe();
Expand Down Expand Up @@ -221,9 +215,6 @@ describe('Subject', function () {
subscription1.unsubscribe();

subject.complete();
subject.next(9);
subject.complete();
subject.error(new Error('err'));

subscription2.unsubscribe();

Expand Down Expand Up @@ -509,6 +500,57 @@ describe('Subject', function () {
source.subscribe(subject);
});

it('should throw ObjectUnsubscribedError when emit after unsubscribed', function () {
var subject = new Rx.Subject();
subject.unsubscribe();

expect(function () {
subject.next('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.error('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.complete();
}).toThrow(new Rx.ObjectUnsubscribedError());
});

it('should throw ObjectUnsubscribedError when emit after completed', function () {
var subject = new Rx.Subject();
subject.complete();

expect(function () {
subject.next('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.error('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.complete();
}).toThrow(new Rx.ObjectUnsubscribedError());
});

it('should throw ObjectUnsubscribedError when emit after error', function () {
var subject = new Rx.Subject();
subject.error('e');

expect(function () {
subject.next('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.error('a');
}).toThrow(new Rx.ObjectUnsubscribedError());

expect(function () {
subject.complete();
}).toThrow(new Rx.ObjectUnsubscribedError());
});

describe('asObservable', function () {
it('should hide subject', function () {
var subject = new Rx.Subject();
Expand Down
12 changes: 6 additions & 6 deletions spec/observables/zip-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,20 @@ describe('Observable.zip', function () {
});

it('should work with non-empty observable and empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [];
var expected = '-----# ';
var expected = '-----#';

expectObservable(Observable.zip(a,b)).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
});

it('should work with observable which raises error and non-empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [1];
var expected = '-----# ';
var expected = '-----#';

expectObservable(Observable.zip(a,b)).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/catch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Observable.prototype.catch()', function () {
});

it('should catch error and replace it with a hot Observable', function () {
var e1 = hot('--a--b--#----| ');
var e1 = hot('--a--b--# ');
var e1subs = '^ ! ';
var e2 = hot('1-2-3-4-5-6-7-8-9-|');
var e2subs = ' ^ !';
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/concatAll-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Observable.prototype.concatAll()', function () {
y: cold( 'a-b---------|'),
z: cold( 'c-d-e-f-|'),
};
var e1 = hot('--y---------z---#-------------|', values);
var e1 = hot('--y---------z---# ', values);
var expected = '--a-b---------c-#';

expectObservable(e1.concatAll()).toBe(expected);
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/groupBy-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions */
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions, rxTestScheduler */
var Rx = require('../../dist/cjs/Rx.KitchenSink');
var Observable = Rx.Observable;
var GroupedObservable = require('../../dist/cjs/operator/groupBy').GroupedObservable;
Expand Down
8 changes: 4 additions & 4 deletions spec/operators/map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Observable.prototype.map()', function () {
});

it('should map with index until completed', function () {
var a = hot('-5-^-4--3---2----1--|--8--|--#');
var a = hot('-5-^-4--3---2----1--|');
var asubs = '^ !';
var expected = '--a--b---c----d--|';
var values = {a: 5, b: 14, c: 23, d: 32};
Expand All @@ -155,7 +155,7 @@ describe('Observable.prototype.map()', function () {
});

it('should map with index until an error occurs', function () {
var a = hot('-5-^-4--3---2----1--#--8--|', undefined, 'too bad');
var a = hot('-5-^-4--3---2----1--#', undefined, 'too bad');
var asubs = '^ !';
var expected = '--a--b---c----d--#';
var values = {a: 5, b: 14, c: 23, d: 32};
Expand All @@ -173,7 +173,7 @@ describe('Observable.prototype.map()', function () {
});

it('should map using a custom thisArg', function () {
var a = hot('-5-^-4--3---2----1--|--8--|--#');
var a = hot('-5-^-4--3---2----1--|');
var asubs = '^ !';
var expected = '--a--b---c----d--|';
var values = {a: 5, b: 14, c: 23, d: 32};
Expand All @@ -195,7 +195,7 @@ describe('Observable.prototype.map()', function () {
});

it('should map twice', function () {
var a = hot('-0----1-^-2---3--4-5--6--7-8-|--9-#-|');
var a = hot('-0----1-^-2---3--4-5--6--7-8-|');
var asubs = '^ !';
var expected = '--a---b--c-d--e--f-g-|';
var values = {a: 2, b: 3, c: 4, d: 5, e: 6, f: 7, g: 8};
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/mergeAll-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('Observable.prototype.mergeAll()', function () {
var ysubs = ' ^ ! ';
var z = cold( 'c-d-e-f-| ');
var zsubs = ' ^ ! ';
var e1 = hot('--y---------z---#-------------|', { y: y, z: z });
var e1 = hot('--y---------z---# ', { y: y, z: z });
var e1subs = '^ ! ';
var expected = '--a-b-------c-d-# ';

Expand Down
4 changes: 2 additions & 2 deletions spec/operators/multicast-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ describe('Observable.prototype.multicast()', function () {
source.connect();
});

it('should not throw `cannot subscribe to a disposed subject` when used in ' +
it('should not throw ObjectUnsubscribedError when used in ' +
'a switchMap', function (done) {
var source = Observable.of(1, 2, 3)
.multicast(function () { return new Subject(); })
Expand Down Expand Up @@ -548,7 +548,7 @@ describe('Observable.prototype.multicast()', function () {
source.connect();
});

it('should not throw `cannot subscribe to a disposed subject` when used in ' +
it('should not throw ObjectUnsubscribedError when used in ' +
'a switchMap', function (done) {
var source = Observable.of(1, 2, 3)
.multicast(new Subject())
Expand Down
8 changes: 6 additions & 2 deletions spec/operators/skipUntil-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,14 @@ describe('Observable.prototype.skipUntil()', function () {
var e1 = hot( '--a--b--c--d--e--|');
var e1subs = ['^ !',
'^ !']; // for the explicit subscribe some lines below
var skip = hot( '-------------x--|');
var skip = new Rx.Subject();
var expected = '-';

e1.subscribe(function () {
e1.subscribe(function (x) {
if (x === 'd' && !skip.isUnsubscribed) {
skip.next('x');
}

skip.unsubscribe();
});

Expand Down
2 changes: 1 addition & 1 deletion spec/operators/takeUntil-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Observable.prototype.takeUntil()', function () {
it('should take values and raises error when notifier raises error', function () {
var e1 = hot('--a--b--c--d--e--f--g--|');
var e1subs = '^ ! ';
var e2 = hot('-------------#--| ');
var e2 = hot('-------------# ');
var e2subs = '^ ! ';
var expected = '--a--b--c--d-# ';

Expand Down
2 changes: 1 addition & 1 deletion spec/operators/window-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('Observable.prototype.window', function () {
rxTestScheduler.schedule(function () {
expect(function () {
window.subscribe();
}).toThrowError('Cannot subscribe to a disposed Subject.');
}).toThrow(new Rx.ObjectUnsubscribedError());
}, late);
});

Expand Down
2 changes: 1 addition & 1 deletion spec/operators/windowCount-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Observable.prototype.windowCount', function () {
rxTestScheduler.schedule(function () {
expect(function () {
window.subscribe();
}).toThrowError('Cannot subscribe to a disposed Subject.');
}).toThrow(new Rx.ObjectUnsubscribedError());
}, late);
});

Expand Down
7 changes: 2 additions & 5 deletions spec/operators/windowTime-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,9 @@ describe('Observable.prototype.windowTime', function () {
expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
rxTestScheduler.schedule(function () {
try {
expect(function () {
window.subscribe();
}
catch (err) {
expect(err.message).toBe('Cannot subscribe to a disposed Subject.');
}
}).toThrow(new Rx.ObjectUnsubscribedError());
}, 150);
});

Expand Down
6 changes: 3 additions & 3 deletions spec/operators/windowToggle-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions */
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions, rxTestScheduler */
var Rx = require('../../dist/cjs/Rx.KitchenSink');
var Observable = Rx.Observable;

Expand Down Expand Up @@ -214,7 +214,7 @@ describe('Observable.prototype.windowToggle', function () {
rxTestScheduler.schedule(function () {
expect(function () {
window.subscribe();
}).toThrowError('Cannot subscribe to a disposed Subject.');
}).toThrow(new Rx.ObjectUnsubscribedError());
}, late);
});

Expand Down Expand Up @@ -284,7 +284,7 @@ describe('Observable.prototype.windowToggle', function () {
});

it('should handle errors', function () {
var e1 = hot('--a--^---b---c---d---e--#f---g---h------|');
var e1 = hot('--a--^---b---c---d---e--# ');
var e1subs = '^ ! ';
var e2 = cold('--x-----------y--------z---| ');
var e2subs = '^ ! ';
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/windowWhen-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Observable.prototype.windowWhen', function () {
rxTestScheduler.schedule(function () {
expect(function () {
window.subscribe();
}).toThrowError('Cannot subscribe to a disposed Subject.');
}).toThrow(new Rx.ObjectUnsubscribedError());
}, late);
});

Expand Down
12 changes: 6 additions & 6 deletions spec/operators/zip-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,20 @@ describe('zip', function () {
});

it('should work with non-empty observable and empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [];
var expected = '-----# ';
var expected = '-----#';

expectObservable(a.zip(b)).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
});

it('should work with observable which raises error and non-empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [1];
var expected = '-----# ';
var expected = '-----#';

expectObservable(a.zip(b)).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
Expand Down
12 changes: 6 additions & 6 deletions spec/operators/zipAll-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ describe('Observable.prototype.zipAll', function () {
});

it('should work with non-empty observable and empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [];
var expected = '-----# ';
var expected = '-----#';

expectObservable(Observable.of(a,b).zipAll()).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
});

it('should work with observable which raises error and non-empty iterable', function () {
var a = hot('---^----#--|');
var asubs = '^ ! ';
var a = hot('---^----#');
var asubs = '^ !';
var b = [1];
var expected = '-----# ';
var expected = '-----#';

expectObservable(Observable.of(a,b).zipAll()).toBe(expected);
expectSubscriptions(a.subscriptions).toBe(asubs);
Expand Down
2 changes: 0 additions & 2 deletions spec/subjects/AsyncSubject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ describe('AsyncSubject', function () {
expect(observer.results).toEqual([]);
subject.complete();
expect(observer.results).toEqual([2, 'done']);
subject.next(3);
expect(observer.results).toEqual([2, 'done']);
});

it('should not emit values if unsubscribed before complete', function () {
Expand Down
5 changes: 4 additions & 1 deletion spec/subjects/BehaviorSubject-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ describe('BehaviorSubject', function () {

subject.next('foo');
subject.complete();
subject.next('bar');

expect(function () {
subject.next('bar');
}).toThrow(new Rx.ObjectUnsubscribedError());
});

it('should clean out unsubscribed subscribers', function (done) {
Expand Down
Loading