Skip to content

Commit

Permalink
fix(mergeWith): works correctly with an Array (#7281)
Browse files Browse the repository at this point in the history
* fix(mergeWith): works correctly with an Array

* test: just use a synchronous test to ensure it doesn't emit more or less than it's supposed to (including emitting undefineds).

* test: fix `mergeWith` test

---------

Co-authored-by: Ben Lesh <ben@benlesh.com>
  • Loading branch information
josepot and benlesh authored Jul 31, 2023
1 parent 9db6563 commit 27855c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 18 additions & 0 deletions spec/operators/mergeWith-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ describe('merge operator', () => {
});
});

it('should merge a source with a second, when the second is just a plain array', (done) => {
const a = of(1, 2, 3);
const b = [4, 5, 6, 7, 8];
const r = [1, 2, 3, 4, 5, 6, 7, 8];

a.pipe(mergeWith(b)).subscribe({
next: (val) => {
expect(val).to.equal(r.shift());
},
error: () => {
done(new Error('should not be called'));
},
complete: () => {
done();
},
});
});

it('should merge cold and cold', () => {
rxTestScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
const e1 = cold(' ---a-----b-----c----|');
Expand Down
2 changes: 0 additions & 2 deletions src/internal/operators/merge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ObservableInput, ObservableInputTuple, OperatorFunction, SchedulerLike } from '../types';
import { operate } from '../util/lift';
import { argsOrArgArray } from '../util/argsOrArgArray';
import { mergeAll } from './mergeAll';
import { popNumber, popScheduler } from '../util/args';
import { from } from '../observable/from';
Expand All @@ -23,7 +22,6 @@ export function merge<T, A extends readonly unknown[]>(
export function merge<T>(...args: unknown[]): OperatorFunction<T, unknown> {
const scheduler = popScheduler(args);
const concurrent = popNumber(args, Infinity);
args = argsOrArgArray(args);

return operate((source, subscriber) => {
mergeAll(concurrent)(from([source, ...(args as ObservableInput<T>[])], scheduler)).subscribe(subscriber);
Expand Down

0 comments on commit 27855c6

Please sign in to comment.