diff --git a/spec/operators/debounce-spec.ts b/spec/operators/debounce-spec.ts index 9c037268df..385e5fd8f3 100644 --- a/spec/operators/debounce-spec.ts +++ b/spec/operators/debounce-spec.ts @@ -44,6 +44,19 @@ describe('Observable.prototype.debounceV5', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + it('should support a scalar selector observable', () => { + + // If the selector returns a scalar observable, the debounce operator + // should emit the value immediately. + + const e1 = hot('--a--bc--d----|'); + const e1subs = '^ !'; + const expected = '--a--bc--d----|'; + + expectObservable(e1.debounce(() => Rx.Observable.of(0))).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); + it('should complete when source does not emit', () => { const e1 = hot('-----|'); const e1subs = '^ !'; diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 127948784d..8477535c0b 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -105,7 +105,7 @@ class DebounceSubscriber extends OuterSubscriber { } subscription = subscribeToResult(this, duration); - if (!subscription.closed) { + if (subscription && !subscription.closed) { this.add(this.durationSubscription = subscription); } }