mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
test(platform-server): fix flaky hydration test (#59579)
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. PR Close #59579
This commit is contained in:
committed by
Pawel Kozlowski
parent
f6e97763cf
commit
8ea691a9d8
@@ -93,18 +93,20 @@ export function hydrate(
|
||||
hydrationFeatures?: () => HydrationFeature<HydrationFeatureKind>[];
|
||||
} = {},
|
||||
) {
|
||||
function _document(): any {
|
||||
ɵsetDocument(doc);
|
||||
global.document = doc; // needed for `DefaultDomRenderer2`
|
||||
return doc;
|
||||
}
|
||||
|
||||
const {envProviders = [], hydrationFeatures = () => []} = options;
|
||||
|
||||
// Apply correct reference to the `document` object,
|
||||
// which will be used by runtime.
|
||||
ɵsetDocument(doc);
|
||||
|
||||
// Define `document` to make `DefaultDomRenderer2` work, since it
|
||||
// references `document` directly to create style tags.
|
||||
global.document = doc;
|
||||
|
||||
const providers = [
|
||||
...envProviders,
|
||||
{provide: PLATFORM_ID, useValue: 'browser'},
|
||||
{provide: DOCUMENT, useFactory: _document, deps: []},
|
||||
{provide: DOCUMENT, useFactory: () => doc},
|
||||
provideClientHydration(...hydrationFeatures()),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user