Skip to content

Commit f70aa94

Browse files
committed
test(platform-server): fix flaky hydration test
This commit updates testing setup logic to apply correct `document` reference, which should be used by the runtime. Previously, the timing of that operation was less predictable and in some cases led to reusing document state from previous tests.
1 parent f6e9776 commit f70aa94

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/platform-server/test/dom_utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,20 @@ export function hydrate(
9393
hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
9494
} = {},
9595
) {
96-
function _document(): any {
97-
ɵsetDocument(doc);
98-
global.document = doc; // needed for `DefaultDomRenderer2`
99-
return doc;
100-
}
101-
10296
const {envProviders = [], hydrationFeatures = () => []} = options;
10397

98+
// Apply correct reference to the `document` object,
99+
// which will be used by runtime.
100+
ɵsetDocument(doc);
101+
102+
// Define `document` to make `DefaultDomRenderer2` work, since it
103+
// references `document` directly to create style tags.
104+
global.document = doc;
105+
104106
const providers = [
105107
...envProviders,
106108
{provide: PLATFORM_ID, useValue: 'browser'},
107-
{provide: DOCUMENT, useFactory: _document, deps: []},
109+
{provide: DOCUMENT, useFactory: () => doc},
108110
provideClientHydration(...hydrationFeatures()),
109111
];
110112

0 commit comments

Comments
 (0)