Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mergeWith): include mergeWith tests from 7.x #7315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/operators/mergeAll-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,21 @@ describe('mergeAll', () => {
});
});

it('should merge an observable and an observable input (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];

of(a, b)
.pipe(mergeAll())
.subscribe({
next: (val) => {
expect(val).to.equal(r.shift());
},
complete: done,
});
});

it('should stop listening to a synchronous observable when unsubscribed', () => {
const sideEffects: number[] = [];
const synchronousObservable = new Observable<number>((subscriber) => {
Expand Down
58 changes: 22 additions & 36 deletions spec/operators/mergeWith-spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from 'chai';
import { mergeWith, map, mergeAll, take } from 'rxjs/operators';
import { mergeWith, map, take } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { queueScheduler, of, scheduled, Observable } from 'rxjs';
import { of, Observable } from 'rxjs';
import { observableMatcher } from '../helpers/observableMatcher';

/** @test {merge} */
describe('merge operator', () => {
/** @test {mergeWith} */
describe('mergeWith', () => {
let rxTestScheduler: TestScheduler;

beforeEach(() => {
Expand Down 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 Expand Up @@ -303,38 +321,6 @@ describe('merge operator', () => {
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
});
});

describe('mergeAll operator', () => {
it('should merge two observables', (done) => {
const a = of(1, 2, 3);
const b = of(4, 5, 6, 7, 8);
const r = [1, 2, 3, 4, 5, 6, 7, 8];

of(a, b)
.pipe(mergeAll())
.subscribe({
next: (val) => {
expect(val).to.equal(r.shift());
},
complete: done,
});
});

it('should merge two immediately-scheduled observables', (done) => {
const a = scheduled([1, 2, 3], queueScheduler);
const b = scheduled([4, 5, 6, 7, 8], queueScheduler);
const r = [1, 2, 4, 3, 5, 6, 7, 8];

scheduled([a, b], queueScheduler)
.pipe(mergeAll())
.subscribe({
next: (val) => {
expect(val).to.equal(r.shift());
},
complete: done,
});
});

it('should stop listening to a synchronous observable when unsubscribed', () => {
const sideEffects: number[] = [];
Expand Down