Please call "TestBed.compileComponents" before your test
This call is required when testing components using templateUrl
Error: Cannot create the component AppComponent as it was not imported into the testing module!
You need to configure the TestBed
before each test, adding any components, modules and services you need for the test. It's just like configuring an regular @NgModule
from scratch, but you just add what you need.
import { async, TestBed } from '@angular/core/testing';
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ],
providers: [],
imports: []
})
.compileComponents();
}));
it('...', () => {
let fixture = TestBed.createComponent(AppComponent);
});
See Also
TestBed.compileComponents()
?TestBed
is a mock environment to run Angular2 component tests without the browser. – Compulsory