Skip to content

Commit 986be2f

Browse files
cartantbenlesh
authored andcommitted
fix(endWith): wrap args - they are not observables - in of before concatenating (#4735)
* test(endWith): add failing test * fix(endWith): wrap args in of before concat * chore(endWith): remove any assertion
1 parent 7926122 commit 986be2f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/operators/endWith-spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ describe('endWith operator', () => {
2020
expectSubscriptions(e1.subscriptions).toBe(e1subs);
2121
});
2222

23+
it('should append numbers to a cold Observable', () => {
24+
const values = { a: 1, b: 2, c: 3, s: 4 };
25+
const e1 = cold('---a--b--c--|', values);
26+
const e1subs = '^ !';
27+
const expected = '---a--b--c--(s|)';
28+
29+
expectObservable(e1.pipe(endWith(values.s))).toBe(expected, values);
30+
expectSubscriptions(e1.subscriptions).toBe(e1subs);
31+
});
32+
2333
it('should end an observable with given value', () => {
2434
const e1 = hot('--a--|');
2535
const e1subs = '^ !';

src/internal/operators/endWith.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Observable } from '../Observable';
22
import { concat } from '../observable/concat';
3+
import { of } from '../observable/of';
34
import { MonoTypeOperatorFunction, SchedulerLike, OperatorFunction } from '../types';
45

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

0 commit comments

Comments
 (0)