diff --git a/spec/observables/combineLatest-spec.ts b/spec/observables/combineLatest-spec.ts index 0612bd0e74..d04f2bd650 100644 --- a/spec/observables/combineLatest-spec.ts +++ b/spec/observables/combineLatest-spec.ts @@ -14,6 +14,50 @@ describe('static combineLatest', () => { rxTestScheduler = new TestScheduler(observableMatcher); }); + it('should return EMPTY if passed an empty array as the only argument', () => { + const results: string[] = []; + combineLatest([]).subscribe({ + next: () => { + throw new Error('should not emit') + }, + complete: () => { + results.push('done'); + } + }); + + expect(results).to.deep.equal(['done']); + }); + + it('should return EMPTY if passed an empty POJO as the only argument', () => { + const results: string[] = []; + combineLatest({}).subscribe({ + next: () => { + throw new Error('should not emit') + }, + complete: () => { + results.push('done'); + } + }); + + expect(results).to.deep.equal(['done']); + }); + + it('should return EMPTY if passed an empty array and scheduler as the only argument', () => { + const results: string[] = []; + combineLatest([], rxTestScheduler).subscribe({ + next: () => { + throw new Error('should not emit') + }, + complete: () => { + results.push('done'); + } + }); + + expect(results).to.deep.equal([]); + rxTestScheduler.flush(); + expect(results).to.deep.equal(['done']); + }); + it('should combineLatest the provided observables', () => { rxTestScheduler.run(({ hot, expectObservable }) => { const firstSource = hot(' ----a----b----c----|'); diff --git a/src/internal/observable/combineLatest.ts b/src/internal/observable/combineLatest.ts index 1dff5ec607..76bc97800f 100644 --- a/src/internal/observable/combineLatest.ts +++ b/src/internal/observable/combineLatest.ts @@ -463,6 +463,13 @@ export function combineLatest, R>(...args: any[]) const { args: observables, keys } = argsArgArrayOrObject(args); + if (observables.length === 0) { + // If no observables are passed, or someone has passed an ampty array + // of observables, or even an empty object POJO, we need to just + // complete (EMPTY), but we have to honor the scheduler provided if any. + return from([], scheduler as any); + } + const result = new Observable[]>( combineLatestInit( observables as ObservableInput>[],