Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit abf550a

Browse filesBrowse files
committed
test(template): rxChunk: test all the strategies
1 parent df9b2c1 commit abf550a
Copy full SHA for abf550a

File tree

1 file changed

+41
-12
lines changed
Filter options

1 file changed

+41
-12
lines changed

‎libs/template/chunk/src/lib/tests/chunk.directive.spec.ts

Copy file name to clipboardExpand all lines: libs/template/chunk/src/lib/tests/chunk.directive.spec.ts
+41-12Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
3-
import { Subject } from 'rxjs';
3+
import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies';
4+
import { delay, Subject } from 'rxjs';
45
import { ChunkModule } from '../chunk.module';
56

67
@Component({
@@ -30,6 +31,7 @@ describe('ChunkDirective', () => {
3031
let fixture: ComponentFixture<ChunkTestComponent>;
3132
let componentInstance: ChunkTestComponent;
3233
let nativeElement: HTMLElement;
34+
let strategyProvider: RxStrategyProvider;
3335

3436
beforeEach(() => {
3537
TestBed.configureTestingModule({
@@ -39,20 +41,27 @@ describe('ChunkDirective', () => {
3941
fixture = TestBed.createComponent(ChunkTestComponent);
4042
componentInstance = fixture.componentInstance;
4143
nativeElement = fixture.nativeElement;
44+
strategyProvider = TestBed.inject(RxStrategyProvider);
4245
});
4346

4447
describe.each([
45-
[undefined] /* <- Invalid strategy should fallback. */,
46-
[''] /* <- Same here. */,
47-
['invalid'] /* <- Same here. */,
48-
['immediate'],
49-
['userBlocking'],
50-
['normal'],
51-
['low'],
52-
['idle'],
53-
])('Stratgy: %s', (strategy: string) => {
48+
[undefined, true] /* <- Invalid strategy should fallback. */,
49+
['', true] /* <- Same here. */,
50+
['invalid', true] /* <- Same here. */,
51+
['immediate', true],
52+
['userBlocking', true],
53+
['normal', true],
54+
['low', true],
55+
['idle', true],
56+
['local', true],
57+
['global', false],
58+
['native', false],
59+
])('Strategy: %s', (strategy: string, scheduled: boolean) => {
5460
it('should render with given strategy', (done) => {
5561
componentInstance.strategy = strategy;
62+
const expectedInitialTemplate = scheduled
63+
? 'not-chunked'
64+
: 'chunked not-chunked';
5665
componentInstance.renderCallback.subscribe(() => {
5766
try {
5867
expect(nativeElement.textContent.trim()).toBe('chunked not-chunked');
@@ -62,11 +71,14 @@ describe('ChunkDirective', () => {
6271
}
6372
});
6473
fixture.detectChanges();
65-
expect(nativeElement.textContent).toBe('not-chunked');
74+
expect(nativeElement.textContent.trim()).toBe(expectedInitialTemplate);
6675
});
6776
it('should render the suspense template sync', (done) => {
6877
componentInstance.strategy = strategy;
6978
componentInstance.withSuspense = true;
79+
const expectedInitialTemplate = scheduled
80+
? 'suspendednot-chunked'
81+
: 'chunked not-chunked';
7082
componentInstance.renderCallback.subscribe(() => {
7183
try {
7284
expect(nativeElement.textContent.trim()).toBe('chunked not-chunked');
@@ -76,7 +88,24 @@ describe('ChunkDirective', () => {
7688
}
7789
});
7890
fixture.detectChanges();
79-
expect(nativeElement.textContent).toBe('suspendednot-chunked');
91+
expect(nativeElement.textContent.trim()).toBe(expectedInitialTemplate);
8092
});
8193
});
94+
95+
it('should not render with noop strategy', (done) => {
96+
componentInstance.strategy = 'noop';
97+
fixture.detectChanges();
98+
expect(nativeElement.textContent).toBe('not-chunked');
99+
strategyProvider
100+
.schedule(() => {})
101+
.pipe(delay(10)) // let's just wait a tiny bit to be sure nothing happens :)
102+
.subscribe(() => {
103+
try {
104+
expect(nativeElement.textContent.trim()).toBe('not-chunked');
105+
done();
106+
} catch (e) {
107+
done(e.message);
108+
}
109+
});
110+
});
82111
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.