Skip to content

Commit 9267b30

Browse files
authored
Merge pull request #2796 from kwonoj/fix-shallow-error
fix(subscribeToResult): throw error in subscriber with inner observable
2 parents de9f2c8 + c935bf5 commit 9267b30

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

spec/util/subscribeToResult-spec.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import {expect} from 'chai';
1+
import { expect } from 'chai';
22
import * as Rx from '../../dist/cjs/Rx';
3-
import {subscribeToResult} from '../../dist/cjs/util/subscribeToResult';
4-
import {OuterSubscriber} from '../../dist/cjs/OuterSubscriber';
5-
import {$$iterator} from '../../dist/cjs/symbol/iterator';
3+
import { subscribeToResult } from '../../dist/cjs/util/subscribeToResult';
4+
import { OuterSubscriber } from '../../dist/cjs/OuterSubscriber';
5+
import { $$iterator } from '../../dist/cjs/symbol/iterator';
66
import $$symbolObservable from 'symbol-observable';
7+
import { Observable } from '../../dist/cjs/Observable';
8+
import { Subject } from '../../dist/cjs/Subject';
79

810
describe('subscribeToResult', () => {
911
it('should synchronously complete when subscribe to scalarObservable', () => {
@@ -59,7 +61,7 @@ describe('subscribeToResult', () => {
5961
});
6062

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

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

106108
const iterable = {
107109
[$$iterator]: () => {
108-
return {
109-
next: () => {
110-
return iteratorResults.shift();
111-
}
112-
};
113-
}};
110+
return {
111+
next: () => {
112+
return iteratorResults.shift();
113+
}
114+
};
115+
}
116+
};
114117

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

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

178181
subscribeToResult(subscriber, null);
179182
});
183+
184+
it('should not swallow exception in inner subscriber', () => {
185+
const source = new Subject();
186+
187+
source.mergeMapTo(Observable.of(1, 2, 3)).subscribe(() => {
188+
throw new Error('meh');
189+
});
190+
191+
expect(() => source.next()).to.throw();
192+
});
180193
});

src/util/subscribeToResult.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
3030
destination.complete();
3131
return null;
3232
} else {
33+
destination.syncErrorThrowable = true;
3334
return result.subscribe(destination);
3435
}
3536
} else if (isArrayLike(result)) {

0 commit comments

Comments
 (0)