Skip to content

Commit

Permalink
test(subscribeToResult): add test cases for subscriber exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Aug 14, 2017
1 parent d7bffa9 commit 731be99
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions spec/util/subscribeToResult-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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';

describe('subscribeToResult', () => {
it('should synchronously complete when subscribe to scalarObservable', () => {
Expand Down Expand Up @@ -59,7 +60,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 +106,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 +179,17 @@ describe('subscribeToResult', () => {

subscribeToResult(subscriber, null);
});

it('should not swallow exception in subscriber', () => {
const subscriber = new OuterSubscriber(x => {
//noop
});
const result = Observable.of(1, 2, 3);

subscribeToResult(subscriber, result);

expect(() => result.subscribe(() => {
throw new Error('meh');
})).to.throw();
});
});

0 comments on commit 731be99

Please sign in to comment.