Skip to content

Commit

Permalink
fix(Subscriber): do not call complete with undefined value param (#2559)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored and benlesh committed May 9, 2017
1 parent ebf6393 commit 3d63de2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 16 additions & 1 deletion spec/Subscriber-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Subscriber', () => {
});

it('should not be closed when other subscriber with same observer instance completes', () => {
let observer = {
const observer = {
next: function () { /*noop*/ }
};

Expand All @@ -97,4 +97,19 @@ describe('Subscriber', () => {
expect(sub1.closed).to.be.false;
expect(sub2.closed).to.be.true;
});

it('should call complete observer without any arguments', () => {
let argument: Array<any> = null;

const observer = {
complete: (...args: Array<any>) => {
argument = args;
}
};

const sub1 = new Subscriber(observer);
sub1.complete();

expect(argument).to.have.lengthOf(0);
});
});
6 changes: 4 additions & 2 deletions src/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ class SafeSubscriber<T> extends Subscriber<T> {
if (!this.isStopped) {
const { _parentSubscriber } = this;
if (this._complete) {
const wrappedComplete = () => this._complete.call(this._context);

if (!_parentSubscriber.syncErrorThrowable) {
this.__tryOrUnsub(this._complete);
this.__tryOrUnsub(wrappedComplete);
this.unsubscribe();
} else {
this.__tryOrSetError(_parentSubscriber, this._complete);
this.__tryOrSetError(_parentSubscriber, wrappedComplete);
this.unsubscribe();
}
} else {
Expand Down

0 comments on commit 3d63de2

Please sign in to comment.