Skip to content

Commit

Permalink
test(forkJoin): add tests with never and with unsubscribing after err…
Browse files Browse the repository at this point in the history
…or (#2394)

Add tests with Observable that never completes, so
that it is clear how forkJoin operator behaves with it.
Add test which shows that forkJoin unsubscribes from
other Observables when one of them errors.
  • Loading branch information
mpodlasin authored and benlesh committed Apr 3, 2017
1 parent f6a4951 commit 524259a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions spec/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,35 @@ describe('Observable.forkJoin', () => {
expectObservable(e1).toBe(expected);
});

it('should not complete when only source never completes', () => {
const e1 = Observable.forkJoin(
hot('--------------')
);
const expected = '-';

expectObservable(e1).toBe(expected);
});

it('should not complete when one of the sources never completes', () => {
const e1 = Observable.forkJoin(
hot('--------------'),
hot('-a---b--c--|')
);
const expected = '-';

expectObservable(e1).toBe(expected);
});

it('should complete when one of the sources never completes but other completes without values', () => {
const e1 = Observable.forkJoin(
hot('--------------'),
hot('------|')
);
const expected = '------|';

expectObservable(e1).toBe(expected);
});

it('should complete if source is not provided', () => {
const e1 = Observable.forkJoin();
const expected = '|';
Expand Down Expand Up @@ -245,6 +274,15 @@ describe('Observable.forkJoin', () => {
expectObservable(e1).toBe(expected);
});

it('should raise error when any of source raises error with source that never completes', () => {
const e1 = Observable.forkJoin(
hot('------#'),
hot('----------'));
const expected = '------#';

expectObservable(e1).toBe(expected);
});

it('should raise error when any of source raises error with selector with empty observable', () => {
function selector(x, y) {
return x + y;
Expand Down Expand Up @@ -297,6 +335,20 @@ describe('Observable.forkJoin', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should unsubscribe other Observables, when one of them errors', () => {
const e1 = hot('--a--^--b--c---d-| ');
const e1subs = '^ ! ';
const e2 = hot('---e-^---f--g-#');
const e2subs = '^ ! ';
const expected = '---------# ';

const result = Observable.forkJoin(e1, e2);

expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should support promises', () => {
type(() => {
/* tslint:disable:no-unused-variable */
Expand Down

0 comments on commit 524259a

Please sign in to comment.