Skip to content

Commit

Permalink
fix(endWith): wrap args - they are not observables - in of before con…
Browse files Browse the repository at this point in the history
…catenating (#4735)

* test(endWith): add failing test

* fix(endWith): wrap args in of before concat

* chore(endWith): remove any assertion
  • Loading branch information
cartant authored and benlesh committed May 2, 2019
1 parent 7926122 commit 986be2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/operators/endWith-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ describe('endWith operator', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should append numbers to a cold Observable', () => {
const values = { a: 1, b: 2, c: 3, s: 4 };
const e1 = cold('---a--b--c--|', values);
const e1subs = '^ !';
const expected = '---a--b--c--(s|)';

expectObservable(e1.pipe(endWith(values.s))).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should end an observable with given value', () => {
const e1 = hot('--a--|');
const e1subs = '^ !';
Expand Down
3 changes: 2 additions & 1 deletion src/internal/operators/endWith.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Observable } from '../Observable';
import { concat } from '../observable/concat';
import { of } from '../observable/of';
import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction } from '../types';

/* tslint:disable:max-line-length */
Expand Down Expand Up @@ -62,5 +63,5 @@ export function endWith<T, Z = T>(...array: Array<Z | SchedulerLike>): OperatorF
* @owner Observable
*/
export function endWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
return (source: Observable<T>) => concat(source, ...(array as any[])) as Observable<T>;
return (source: Observable<T>) => concat(source, of(...array)) as Observable<T>;
}

1 comment on commit 986be2f

@Brooooooklyn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a patch version after this fix, or all endWith usage would broken after upgrade to latest RxJS

Please sign in to comment.