From 296637b6c55be0b17d93cdbda18bac740dc4b857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Sat, 9 May 2020 16:06:08 +0200 Subject: [PATCH] Add tests related to internal state --- spec/retryBackoff-spec.ts | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/retryBackoff-spec.ts b/spec/retryBackoff-spec.ts index aae3ab1..db13abb 100644 --- a/spec/retryBackoff-spec.ts +++ b/spec/retryBackoff-spec.ts @@ -350,4 +350,53 @@ describe('retryBackoff operator', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); }); + + it('should be referentially transparent', () => { + testScheduler.run(({ expectObservable, cold, expectSubscriptions }) => { + const source1 = cold('--#'); + const source2 = cold('--#'); + const unsub = ' ---------!'; + const subs = [ + ' ^-! ', + ' ---^-! ', + ' -------^-!', + ]; + const expected = ' ----------'; + + const op = retryBackoff({ + initialInterval: 1, + }); + + expectObservable(source1.pipe(op), unsub).toBe(expected); + expectSubscriptions(source1.subscriptions).toBe(subs); + + expectObservable(source2.pipe(op), unsub).toBe(expected); + expectSubscriptions(source2.subscriptions).toBe(subs); + }); + }); + + it('should ensure interval state is per-subscription', () => { + testScheduler.run(({ expectObservable, cold, expectSubscriptions }) => { + const source = cold('--#'); + const sub1 = ' ^--------!'; + const sub2 = ' ----------^--------!'; + const subs = [ + ' ^-! ', + ' ---^-! ', + ' -------^-!', + ' ----------^-! ', + ' -------------^-! ', + ' -----------------^-!', + ]; + const expected = ' ----------'; + + const result = source.pipe(retryBackoff({ + initialInterval: 1, + })); + + expectObservable(result, sub1).toBe(expected); + expectObservable(result, sub2).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(subs); + }); + }); });