I am starting to use tests in my angular 6 application. I have run into an error though that I am not sure how to solve.
As you can see below my test is complaining that the base href is not set, but in my index.html I do have <base href="/">
Error: No base href set. Please provide a value for the APP_BASE_HREF token or
add a base element to the document.
at new PathLocationStrategy (./node_modules/@angular/common/fesm5/common.js?:498:19)
at provideLocationStrategy (./node_modules/@angular/router/fesm5/router.js?:5302:9)
at _callFactory (./node_modules/@angular/core/fesm5/core.js?:8735:20)
at _createProviderInstance (./node_modules/@angular/core/fesm5/core.js?:8687:26)
at initNgModule (./node_modules/@angular/core/fesm5/core.js?:8617:32)
at new NgModuleRef_ (./node_modules/@angular/core/fesm5/core.js?:9343:9)
at createNgModuleRef (./node_modules/@angular/core/fesm5/core.js?:9332:12)
at Object.debugCreateNgModuleRef [as createNgModuleRef]
(./node_modules/@angular/core/fesm5/core.js?:11157:12)
at NgModuleFactory_.create (./node_modules/@angular/core/fesm5/core.js?:11874:25)
at TestBed._initIfNeeded (./node_modules/@angular/core/fesm5/testing.js?:1015:47)
This is my item-component.spec.ts
test
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ItemComponent} from './item.component';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {AppRoutingModule} from '../../app-routing.module';
import {HomeComponent} from '../home/home.component';
import {ContactComponent} from '../contact/contact.component';
import {InventoryComponent} from '../inventory/inventory.component';
import {SearchComponent} from '../search/search.component';
import {ApplicationFormComponent} from '../application/application-form.component';
import {SiteShellComponent} from '../site-shell/site-shell.component';
import {MainNavigationComponent} from '../partials/main-navigation/main-navigation.component';
import {FooterComponent} from '../partials/footer/footer.component';
import {ReactiveFormsModule} from '@angular/forms';
import {DebugComponent} from '../debug/debug.component';
import {NewformComponent} from '../debug/under-test/newform.component';
import {MultiSelectComponent} from '../debug/under-test/multi-select.component';
describe('ItemComponent', () => {
let component: ItemComponent;
let fixture: ComponentFixture<ItemComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ItemComponent,
HomeComponent,
ContactComponent,
InventoryComponent,
SearchComponent,
FinanceApplicationComponent,
SiteShellComponent,
MainNavigationComponent,
FooterComponent,
DebugComponent,
NewformComponent,
MultiSelectComponent,
],
imports: [
HttpClientTestingModule,
AppRoutingModule,
ReactiveFormsModule
],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ItemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
How come my test cannot see the base href, or what am I doing wrong? I am really not sure what to look at here to fix. I tried importing AppComponent, but that did not help.
Aucun commentaire:
Enregistrer un commentaire