i'm a complete newbie in Angular2 especially in Testing. I've searched the web for a solution but there is so much old code examples that doesn't work anymore. So I came here to ask you.
When i ran my test with "karma test". I get the following error:
Error: Error in ./NavbarItemComponent class NavbarItemComponent - inline template:1:1 caused by: undefined is not an object (evaluating 'config.forEach') in config/karma/karma-test-shim.js (line 20623)
app.component.spec.ts
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NavbarVerticalComponent } from './navbar-vertical/navbar-vertical.component';
import { NavbarItemComponent } from './navbar-item/navbar-item.component';
import { Router } from '@angular/router'
import { RouterTestingModule } from '@angular/router/testing';
class MockRouter extends Router {
navigate = jasmine.createSpy('navigate');
routerState: RouterState;
}
describe('App', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AppComponent, NavbarVerticalComponent, NavbarItemComponent ],
providers: [
{ provide: Router, useClass: MockRouter }
],
imports: [RouterTestingModule]
});
});
it ('should work', () => {
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
});
Aucun commentaire:
Enregistrer un commentaire