Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update refCount tests to run mode #6687

Merged
merged 1 commit into from Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 24 additions & 27 deletions 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,
Expand All @@ -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<boolean>(observer => {
const connectable = new Observable<boolean>((observer) => {
observer.next(true);
return () => {
unsubscribeCalled = true;
Expand All @@ -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);
});

Expand All @@ -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<boolean>(observer => {
const connectable = new Observable<boolean>((observer) => {
observer.next(true);
return () => {
unsubscribeCalled = true;
Expand All @@ -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<string>();
const connectable = subject.pipe(publishReplay(1));
Expand Down