Skip to content

Commit

Permalink
test(shareReplay): improve tests by checking on source subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
josepot committed May 27, 2020
1 parent ce1dc54 commit f771c8b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/operators/shareReplay-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ describe('shareReplay operator', () => {

it('should not restart due to unsubscriptions if refCount is false', () => {
const source = cold('a-b-c-d-e-f-g-h-i-j');
const sourceSubs = '^------------------';
const sub1 = '^------!';
const expected1 = 'a-b-c-d-';
const sub2 = '-----------^-------';
Expand All @@ -184,10 +185,14 @@ describe('shareReplay operator', () => {

expectObservable(shared, sub1).toBe(expected1);
expectObservable(shared, sub2).toBe(expected2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});

it('should restart due to unsubscriptions if refCount is true', () => {
const sourceSubs = [];
const source = cold('a-b-c-d-e-f-g-h-i-j');
sourceSubs.push( '^------!----------------------');
sourceSubs.push( '-----------^------------------');
const sub1 = '^------!';
const expected1 = 'a-b-c-d-';
const sub2 = '-----------^------------------';
Expand All @@ -197,6 +202,7 @@ describe('shareReplay operator', () => {

expectObservable(shared, sub1).toBe(expected1);
expectObservable(shared, sub2).toBe(expected2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});

it('should not restart due to unsubscriptions if refCount is true when the source has completed', () => {
Expand All @@ -216,6 +222,7 @@ describe('shareReplay operator', () => {

it('should default to refCount being false', () => {
const source = cold('a-b-c-d-e-f-g-h-i-j');
const sourceSubs = '^------------------';
const sub1 = '^------!';
const expected1 = 'a-b-c-d-';
const sub2 = '-----------^-------';
Expand All @@ -225,6 +232,7 @@ describe('shareReplay operator', () => {

expectObservable(shared, sub1).toBe(expected1);
expectObservable(shared, sub2).toBe(expected2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});

it('should not break lift() composability', (done: MochaDone) => {
Expand Down

0 comments on commit f771c8b

Please sign in to comment.