Skip to content

Commit

Permalink
fix(merge): return Observable when called with single lowerCaseO
Browse files Browse the repository at this point in the history
Return Observable when merge is called with single lower case observable,
so that merge would always return Observable instance.
  • Loading branch information
mpodlasin committed Feb 12, 2017
1 parent 31dfc73 commit 85752eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 1 addition & 2 deletions spec/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {$$iterator} from '../../dist/cjs/symbol/iterator';
import $$symbolObservable from 'symbol-observable';

export function lowerCaseO<T>(...args): Rx.Observable<T> {
const values = [].slice.apply(arguments);

const o = {
subscribe: function (observer) {
values.forEach(function (v) {
args.forEach(function (v) {
observer.next(v);
});
observer.complete();
Expand Down
31 changes: 31 additions & 0 deletions spec/observables/merge-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import {lowerCaseO} from '../helpers/test-helper';
import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports

declare const hot: typeof marbleTestingSignature.hot;
Expand Down Expand Up @@ -210,6 +211,36 @@ describe('Observable.merge(...observables)', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should merge single lowerCaseO into RxJS Observable', () => {
const e1 = lowerCaseO('a', 'b', 'c');

const result = Observable.merge(e1);

expect(result).to.be.instanceof(Observable);
expectObservable(result).toBe('(abc|)');
});

it('should merge two lowerCaseO into RxJS Observable', () => {
const e1 = lowerCaseO('a', 'b', 'c');
const e2 = lowerCaseO('d', 'e', 'f');

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

expect(result).to.be.instanceof(Observable);
expectObservable(result).toBe('(abcdef|)');
});
});

describe('Observable.merge(...observables, Scheduler)', () => {
it('should merge single lowerCaseO into RxJS Observable', () => {
const e1 = lowerCaseO('a', 'b', 'c');

const result = Observable.merge(e1, rxTestScheduler);

expect(result).to.be.instanceof(Observable);
expectObservable(result).toBe('(abc|)');
});
});

describe('Observable.merge(...observables, Scheduler, number)', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function mergeStatic<T, R>(...observables: Array<ObservableInput<any> | I
concurrent = <number>observables.pop();
}

if (scheduler === null && observables.length === 1) {
if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
return <Observable<R>>observables[0];
}

Expand Down

0 comments on commit 85752eb

Please sign in to comment.