From ca42280fbccfac3f9d9ba4ed95942b31043fc9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 12 Jan 2021 22:28:26 +0100 Subject: [PATCH] chore: update ignoreElements tests to run mode --- spec/operators/ignoreElements-spec.ts | 128 +++++++++++++++----------- 1 file changed, 75 insertions(+), 53 deletions(-) diff --git a/spec/operators/ignoreElements-spec.ts b/spec/operators/ignoreElements-spec.ts index 6f75c8bcdc..34f0ff2a78 100644 --- a/spec/operators/ignoreElements-spec.ts +++ b/spec/operators/ignoreElements-spec.ts @@ -1,79 +1,101 @@ +/** @prettier */ import { ignoreElements, mergeMap } from 'rxjs/operators'; -import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; +import { TestScheduler } from 'rxjs/testing'; import { of } from 'rxjs'; +import { observableMatcher } from '../helpers/observableMatcher'; /** @test {ignoreElements} */ -describe('ignoreElements operator', () => { - it('should ignore all the elements of the source', () => { - const source = hot('--a--b--c--d--|'); - const subs = '^ !'; - const expected = '--------------|'; +describe('ignoreElements', () => { + let testScheduler: TestScheduler; + + beforeEach(() => { + testScheduler = new TestScheduler(observableMatcher); + }); - expectObservable(source.pipe(ignoreElements())).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + it('should ignore all the elements of the source', () => { + testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { + const e1 = hot(' --a--b--c--d--|'); + const e1subs = ' ^-------------!'; + const expected = '--------------|'; + + expectObservable(e1.pipe(ignoreElements())).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); it('should allow unsubscribing early and explicitly', () => { - const source = hot('--a--b--c--d--|'); - const subs = '^ ! '; - const expected = '-------- '; - const unsub = ' ! '; + testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { + const e1 = hot(' --a--b--c--d--|'); + const e1subs = ' ^------! '; + const expected = '-------- '; + const unsub = ' -------! '; - const result = source.pipe(ignoreElements()); + const result = e1.pipe(ignoreElements()); - expectObservable(result, unsub).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + expectObservable(result, unsub).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); - it('should allow unsubscribing early and explicitly', () => { - const source = hot('--a--b--c--d--|'); - const subs = '^ ! '; - const expected = '-------- '; - const unsub = ' ! '; - - const result = source.pipe( - mergeMap((x: string) => of(x)), - ignoreElements(), - mergeMap((x: string) => of(x)) - ); - - expectObservable(result, unsub).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + it('should allow unsubscribing early and explicitly with higher order', () => { + testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { + const e1 = hot(' --a--b--c--d--|'); + const e1subs = ' ^------! '; + const expected = '-------- '; + const unsub = ' -------! '; + + const result = e1.pipe( + mergeMap((x) => of(x)), + ignoreElements(), + mergeMap((x) => of(x)) + ); + + expectObservable(result, unsub).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); it('should propagate errors from the source', () => { - const source = hot('--a--#'); - const subs = '^ !'; - const expected = '-----#'; - - expectObservable(source.pipe(ignoreElements())).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { + const e1 = hot(' --a--#'); + const e1subs = ' ^----!'; + const expected = '-----#'; + + expectObservable(e1.pipe(ignoreElements())).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); - it('should support Observable.empty', () => { - const source = cold('|'); - const subs = '(^!)'; - const expected = '|'; + it('should handle empty', () => { + testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { + const e1 = cold(' | '); + const e1subs = ' (^!)'; + const expected = '| '; - expectObservable(source.pipe(ignoreElements())).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + expectObservable(e1.pipe(ignoreElements())).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); - it('should support Observable.never', () => { - const source = cold('-'); - const subs = '^'; - const expected = '-'; + it('should handle never', () => { + testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { + const e1 = cold(' -'); + const e1subs = ' ^'; + const expected = '-'; - expectObservable(source.pipe(ignoreElements())).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + expectObservable(e1.pipe(ignoreElements())).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); - it('should support Observable.throw', () => { - const source = cold('#'); - const subs = '(^!)'; - const expected = '#'; + it('should handle throw', () => { + testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { + const e1 = cold(' # '); + const e1subs = ' (^!)'; + const expected = '# '; - expectObservable(source.pipe(ignoreElements())).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(subs); + expectObservable(e1.pipe(ignoreElements())).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); }); });