diff --git a/spec/operators/retry-spec.ts b/spec/operators/retry-spec.ts index 8826c8155a..8cdd25b893 100644 --- a/spec/operators/retry-spec.ts +++ b/spec/operators/retry-spec.ts @@ -326,4 +326,17 @@ describe('retry operator', () => { expect(sideEffects).to.deep.equal([0, 1, 2]); }); + + it('should not alter the source when the number of retries is smaller than 1', () => { + const source = cold('--1-2-3-#'); + const subs = ['^ !']; + + const expected = '--1-2-3-#'; + const unsub = ' !'; + + const result = source.pipe(retry(0)); + + expectObservable(result, unsub).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(subs); + }) }); diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index 3a9dbe7ce4..9d41a4d210 100644 --- a/src/internal/operators/retry.ts +++ b/src/internal/operators/retry.ts @@ -1,8 +1,8 @@ import { MonoTypeOperatorFunction } from '../types'; import { operate } from '../util/lift'; import { Subscription } from '../Subscription'; -import { EMPTY } from '../observable/empty'; import { OperatorSubscriber } from './OperatorSubscriber'; +import { identity } from '../util/identity'; export interface RetryConfig { count: number; @@ -69,7 +69,7 @@ export function retry(configOrCount: number | RetryConfig = Infinity): MonoTy const { count, resetOnSuccess = false } = config; return count <= 0 - ? () => EMPTY + ? identity : operate((source, subscriber) => { let soFar = 0; let innerSub: Subscription | null;