Skip to content

Commit 7e10488

Browse files
committed
test(platform-server): fix flaky incremental hydration test
This commit updates a test setup to define a global `ngServerMode` correctly for a test that was emulating client-only behavior. The flag could've been set by prior tests and depending on its state, the test was acting differently.
1 parent f6e9776 commit 7e10488

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

packages/platform-server/test/incremental_hydration_spec.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,9 @@ describe('platform-server partial hydration integration', () => {
18221822

18231823
describe('client side navigation', () => {
18241824
beforeEach(() => {
1825+
// This test emulates client-side behavior, set global server mode flag to `false`.
1826+
globalThis['ngServerMode'] = false;
1827+
18251828
TestBed.configureTestingModule({
18261829
providers: [
18271830
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
@@ -1830,32 +1833,28 @@ describe('platform-server partial hydration integration', () => {
18301833
});
18311834
});
18321835

1836+
afterEach(() => {
1837+
globalThis['ngServerMode'] = undefined;
1838+
});
1839+
18331840
it('should not try to hydrate in CSR only cases', async () => {
18341841
@Component({
18351842
selector: 'app',
18361843
template: `
1837-
<main (click)="fnA()">
1838-
@defer (hydrate when true) {
1839-
<article>
1840-
defer block rendered!
1841-
<span id="test" (click)="fnB()">{{value()}}</span>
1842-
</article>
1843-
} @placeholder {
1844-
<span>Outer block placeholder</span>
1845-
}
1846-
</main>
1844+
@defer (hydrate when true; on interaction) {
1845+
<p>Defer block rendered!</p>
1846+
} @placeholder {
1847+
<span>Outer block placeholder</span>
1848+
}
18471849
`,
18481850
})
1849-
class SimpleComponent {
1850-
value = signal('start');
1851-
fnA() {}
1852-
fnB() {
1853-
this.value.set('end');
1854-
}
1855-
}
1851+
class SimpleComponent {}
1852+
18561853
const fixture = TestBed.createComponent(SimpleComponent);
18571854
fixture.detectChanges();
18581855

1856+
// Verify that `hydrate when true` doesn't trigger rendering of the main
1857+
// content in client-only use-cases (expecting to see placeholder content).
18591858
expect(fixture.nativeElement.innerHTML).toContain('Outer block placeholder');
18601859
});
18611860
});

0 commit comments

Comments
 (0)