From ba8c4d1d7d67bce1ae726d4395939f731cffe348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Mon, 22 Nov 2021 14:15:32 +0100 Subject: [PATCH] chore: update refCount tests to run mode --- spec/operators/refCount-spec.ts | 51 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/spec/operators/refCount-spec.ts b/spec/operators/refCount-spec.ts index 170806803e..70cee868f7 100644 --- a/spec/operators/refCount-spec.ts +++ b/spec/operators/refCount-spec.ts @@ -1,33 +1,33 @@ +/** @prettier */ import { expect } from 'chai'; -import { cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; -import { refCount, publish, publishReplay, first, multicast, take } from 'rxjs/operators'; +import { TestScheduler } from 'rxjs/testing'; +import { refCount, publish, publishReplay, first } from 'rxjs/operators'; import { NEVER, noop, Observable, Subject } from 'rxjs'; +import { observableMatcher } from '../helpers/observableMatcher'; /** @test {refCount} */ describe('refCount', () => { - it('should turn a multicasted Observable an automatically ' + - '(dis)connecting hot one', () => { - const source = cold('--1-2---3-4--5-|'); - const sourceSubs = '^ !'; - const expected = '--1-2---3-4--5-|'; - - const result = source.pipe( - publish(), - refCount() - ); - - expectObservable(result).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); + it('should turn a multicasted Observable an automatically (dis)connecting hot one', () => { + const testScheduler = new TestScheduler(observableMatcher); + + testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { + const e1 = cold(' --1-2---3-4--5-|'); + const e1Subs = ' ^--------------!'; + const expected = '--1-2---3-4--5-|'; + + const result = e1.pipe(publish(), refCount()); + + expectObservable(result).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1Subs); + }); }); it('should count references', () => { const connectable = NEVER.pipe(publish()); - const refCounted = connectable.pipe( - refCount() - ); + const refCounted = connectable.pipe(refCount()); const sub1 = refCounted.subscribe({ - next: noop + next: noop, }); const sub2 = refCounted.subscribe({ next: noop, @@ -45,7 +45,7 @@ describe('refCount', () => { it('should unsub from the source when all other subscriptions are unsubbed', (done) => { let unsubscribeCalled = false; - const connectable = new Observable(observer => { + const connectable = new Observable((observer) => { observer.next(true); return () => { unsubscribeCalled = true; @@ -60,7 +60,7 @@ describe('refCount', () => { const sub2 = refCounted.subscribe(() => { //noop }); - const sub3 = refCounted.subscribe((x: any) => { + const sub3 = refCounted.subscribe(() => { expect((connectable as any)._refCount).to.equal(1); }); @@ -73,10 +73,9 @@ describe('refCount', () => { done(); }); - it('should not unsubscribe when a subscriber synchronously unsubscribes if ' + - 'other subscribers are present', () => { + it('should not unsubscribe when a subscriber synchronously unsubscribes if other subscribers are present', () => { let unsubscribeCalled = false; - const connectable = new Observable(observer => { + const connectable = new Observable((observer) => { observer.next(true); return () => { unsubscribeCalled = true; @@ -92,9 +91,7 @@ describe('refCount', () => { expect(unsubscribeCalled).to.be.false; }); - it('should not unsubscribe when a subscriber synchronously unsubscribes if ' + - 'other subscribers are present and the source is a Subject', () => { - + it('should not unsubscribe when a subscriber synchronously unsubscribes if other subscribers are present and the source is a Subject', () => { const arr: string[] = []; const subject = new Subject(); const connectable = subject.pipe(publishReplay(1));