typescript - Angular birim testinde route redirectTo ile tanımlanan rota yerine kökte takılıyor
Bir direktifi birim test etmeye çalışıyorum ama yönlendirme kurulumu ile ilgili garip bir sorun yaşıyorum. path: '' için foo yönlendirmesine rağmen, test durumunun içinde günlüğe kaydettiğimde yol hâlâ /.
Yani sorum şu: Günlük kaydını tuttuğumda neden rota foo değil?
describe('IsRouteDirective', () => {
let directive: IsRouteDirective;
let hostElement: DebugElement;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes([
{
path: '',
pathMatch: 'full',
redirectTo: 'foo'
},
{
path: 'foo',
component: LibRouteComponent
},
{
path: 'bar',
component: LibRouteComponent
}
])
],
declarations: [
LibTestComponent,
LibRouteComponent,
IsRouteDirective
]
});
});
it('should have a class called \'is-route\'', async(() => {
// helper function that calls TestBed.overrideComponent, TestBed.compileComponents, TestBed.createComponent and returns the ComponentFixture
overrideAndCompileComponent(LibTestComponent, `
<div [libIsRoute]="['foo']"></div>
<router-outlet></router-outlet>
`).then((fixture) => {
hostElement = fixture.debugElement.query(By.directive(IsRouteDirective));
directive = hostElement.injector.get(IsRouteDirective);
fixture.detectChanges();
const injector = getTestBed();
const router = injector.get(Router);
// logs '/'
console.log(router.url);
});
}));
});
Bir de {path: ''**'', redirectTo: ''foo''} kullanmayı denedim ama hâlâ / veriyor.