Я хочу проверить маршрутизацию.Я попробовал этот скрипт:
describe('Router: App', () => {
let location: Location;
let router: Router;
let fixture;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AlarmsTableComponent,
AddAlarmsFormComponent,
EditAlarmsFormComponent,
LoginComponent,
DataFilterPipe
],
imports: [RouterTestingModule, DataTableModule, ReactiveFormsModule, FormsModule, HttpClientTestingModule, HttpModule],
providers: [Location, LocationStrategy, AlarmsService, DataFilterPipe, AuthService, ConnectionBackend, HttpModule,
{
provide: APP_BASE_HREF, useValue: '/page' }
]
});
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(MainComponent);
router.initialNavigation();
});
it('navigate to "" redirects you to /page', fakeAsync(() => {
router.navigate(['page']);
tick();
expect(location.path()).toBe('/page');
}));
});
Когда я ng test
, результатом является эта ошибка:
TypeError: this._platformStrategy.getBaseHref не является функцией
Редактировать:
describe('Router: App', () => {
let location: Location;
let router: Router;
let fixture;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AlarmsTableComponent,
AddAlarmsFormComponent,
EditAlarmsFormComponent,
LoginComponent,
DataFilterPipe
],
imports: [RouterTestingModule, DataTableModule, ReactiveFormsModule, FormsModule, HttpClientTestingModule, HttpModule],
providers: [Location, AuthService, AlarmsService, DataFilterPipe,
{provide: LocationStrategy, useClass: PathLocationStrategy }],
});
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(MainComponent);
router.initialNavigation();
});
it('navigate to "" redirects you to /page', fakeAsync(() => {
router.navigate(['page']);
tick();
expect(location.path()).toBe('/page');
}));
});
А теперь показать это:
Ошибка: не задан базовый href.Укажите значение для токена APP_BASE_HREF или добавьте базовый элемент в документ.