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(subscribeToResult): throw error in subscriber with inner observable #2796

Merged
merged 2 commits into from
Aug 17, 2017
Merged
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
35 changes: 24 additions & 11 deletions spec/util/subscribeToResult-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {expect} from 'chai';
import { expect } from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import {subscribeToResult} from '../../dist/cjs/util/subscribeToResult';
import {OuterSubscriber} from '../../dist/cjs/OuterSubscriber';
import {$$iterator} from '../../dist/cjs/symbol/iterator';
import { subscribeToResult } from '../../dist/cjs/util/subscribeToResult';
import { OuterSubscriber } from '../../dist/cjs/OuterSubscriber';
import { $$iterator } from '../../dist/cjs/symbol/iterator';
import $$symbolObservable from 'symbol-observable';
import { Observable } from '../../dist/cjs/Observable';
import { Subject } from '../../dist/cjs/Subject';

describe('subscribeToResult', () => {
it('should synchronously complete when subscribe to scalarObservable', () => {
Expand Down Expand Up @@ -59,7 +61,7 @@ describe('subscribeToResult', () => {
});

it('should subscribe to an array-like and emit synchronously', () => {
const result = {0: 0, 1: 1, 2: 2, length: 3};
const result = { 0: 0, 1: 1, 2: 2, length: 3 };
const expected = [];

const subscriber = new OuterSubscriber(x => expected.push(x));
Expand Down Expand Up @@ -105,12 +107,13 @@ describe('subscribeToResult', () => {

const iterable = {
[$$iterator]: () => {
return {
next: () => {
return iteratorResults.shift();
}
};
}};
return {
next: () => {
return iteratorResults.shift();
}
};
}
};

const subscriber = new OuterSubscriber((x: number) => expected = x);

Expand Down Expand Up @@ -177,4 +180,14 @@ describe('subscribeToResult', () => {

subscribeToResult(subscriber, null);
});

it('should not swallow exception in inner subscriber', () => {
const source = new Subject();

source.mergeMapTo(Observable.of(1, 2, 3)).subscribe(() => {
throw new Error('meh');
});

expect(() => source.next()).to.throw();
});
});
1 change: 1 addition & 0 deletions src/util/subscribeToResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
destination.complete();
return null;
} else {
destination.syncErrorThrowable = true;
return result.subscribe(destination);
}
} else if (isArrayLike(result)) {
Expand Down