After migrating to standalone components in Angular, how do we mock testing routes?
Let's consider a component
@Component({
standalone: true,
imports: [RouterModule]
template: `<a [routerLink]="elsewhere"/>`,
})
class FooComponent {}
configurations of the test that doesn't work anymore...
beforeEach(() => {
TestBed.overrideComponent(FooComponent, {
set: {
//not possible because of type error
imports: [RouterTestingModule.withRoutes([...])],
},
}).configureTestingModule({
imports: [FooComponent],
});
});
beforeEach(() => {
TestBed.configureTestingModule({
//no effect, in my opinion component still imports the real RouterModule
imports: [FooComponent, RouterTestingModule.withRoutes([...])],
});
});
beforeEach(() => {
TestBed.overrideComponent(FooComponent, {
set: {
imports: [RouterTestingModule],
providers: [
provideRoutes([...]) //doesn't have any effect
],
},
}).configureTestingModule({
imports: [FooComponent],
});
});
beforeEach(() => {
TestBed.overrideComponent(FooComponent, {
set: {
imports: [],
providers: [
provideRouter([...]) //doesn't have any effect
],
},
}).configureTestingModule({
imports: [FooComponent],
});
});
anyone have working solution for this?