Skip to content

Commit

Permalink
fix(concat): will now return Observable when given a single object im…
Browse files Browse the repository at this point in the history
…plementing Symbol.observable (#2387)

When static concat is called with single lower case observable,
adapt it to RxJS Observable, so that operator would always return
an Observable instance.
  • Loading branch information
mpodlasin authored and benlesh committed Feb 21, 2017
1 parent c806cc6 commit f5d035a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions spec/observables/concat-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 @@ -367,4 +368,20 @@ describe('Observable.concat', () => {

expect(e1Subscribed).to.be.false;
});

it('should return passed observable if no scheduler was passed', () => {
const source = cold('--a---b----c---|');
const result = Observable.concat(source);

expect(result).to.equal(source);
expectObservable(result).toBe('--a---b----c---|');
});

it('should return RxJS Observable when single lowerCaseO was passed', () => {
const source = lowerCaseO('a', 'b', 'c');
const result = Observable.concat(source);

expect(result).to.be.an.instanceof(Observable);
expectObservable(result).toBe('(abc|)');
});
});
2 changes: 1 addition & 1 deletion src/operator/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function concatStatic<T, R>(...observables: Array<ObservableInput<any> |
scheduler = args.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 f5d035a

Please sign in to comment.