refactor(ct-angular): remove router-specific code
This commit is contained in:
parent
237d065c8e
commit
9df69000e2
|
|
@ -28,7 +28,6 @@ import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting,
|
platformBrowserDynamicTesting,
|
||||||
} from '@angular/platform-browser-dynamic/testing';
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
|
|
||||||
getTestBed().initTestEnvironment(
|
getTestBed().initTestEnvironment(
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
|
|
@ -106,9 +105,6 @@ async function __pwRenderComponent(component) {
|
||||||
|
|
||||||
__pwUpdateSlots(WrapperComponent, component.slots, componentMetadata.selector);
|
__pwUpdateSlots(WrapperComponent, component.slots, componentMetadata.selector);
|
||||||
|
|
||||||
// TODO: only inject when router is provided
|
|
||||||
TestBed.inject(Router).initialNavigation();
|
|
||||||
|
|
||||||
const fixture = TestBed.createComponent(WrapperComponent);
|
const fixture = TestBed.createComponent(WrapperComponent);
|
||||||
fixture.nativeElement.id = 'root';
|
fixture.nativeElement.id = 'root';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import '@angular/compiler';
|
import '@angular/compiler';
|
||||||
import { beforeMount, afterMount } from '@playwright/experimental-ct-angular/hooks';
|
import { beforeMount, afterMount } from '@playwright/experimental-ct-angular/hooks';
|
||||||
import { provideRouter } from '@angular/router';
|
import { Router, provideRouter } from '@angular/router';
|
||||||
import { ButtonComponent } from '@/components/button.component';
|
import { ButtonComponent } from '@/components/button.component';
|
||||||
import { TOKEN } from '@/components/inject.component';
|
import { TOKEN } from '@/components/inject.component';
|
||||||
import { routes } from '@/router';
|
import { routes } from '@/router';
|
||||||
import '@/assets/styles.css';
|
import '@/assets/styles.css';
|
||||||
|
import { APP_INITIALIZER, inject } from '@angular/core';
|
||||||
|
|
||||||
export type HooksConfig = {
|
export type HooksConfig = {
|
||||||
routing?: boolean;
|
routing?: boolean;
|
||||||
|
|
@ -18,7 +19,17 @@ beforeMount<HooksConfig>(async ({ hooksConfig, TestBed }) => {
|
||||||
|
|
||||||
if (hooksConfig?.routing)
|
if (hooksConfig?.routing)
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [provideRouter(routes)],
|
providers: [
|
||||||
|
provideRouter(routes),
|
||||||
|
{
|
||||||
|
provide: APP_INITIALIZER,
|
||||||
|
multi: true,
|
||||||
|
useFactory() {
|
||||||
|
const router = inject(Router);
|
||||||
|
return () => router.initialNavigation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hooksConfig?.injectToken)
|
if (hooksConfig?.injectToken)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue