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