Skip to content

Commit

Permalink
Merge pull request #2796 from kwonoj/fix-shallow-error
Browse files Browse the repository at this point in the history
fix(subscribeToResult): throw error in subscriber with inner observable
  • Loading branch information
benlesh authored Aug 17, 2017
2 parents de9f2c8 + c935bf5 commit 9267b30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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

0 comments on commit 9267b30

Please sign in to comment.