我是刚接触Angular 2的Jasmine,在编写测试用例时,我经常使用TestBed对象并得到错误:Please call "TestBed.compileComponents" before your test.
如何解决此错误?
@Component({
moduleId:module.id,
selector: 'my-app',
templateUrl: 'app-component.html',
})发布于 2016-10-06 16:32:35
请在测试前调用"TestBed.compileComponents“
使用templateUrl测试组件时,此调用是必需的
错误:组件AppComponent未导入测试模块,无法创建!
您需要在每次测试之前配置TestBed,添加测试所需的任何组件、模块和服务。这就像是从头开始配置一个常规的@NgModule,但您只需添加所需的内容。
import { async, TestBed } from '@angular/core/testing';
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ],
providers: [],
imports: []
})
.compileComponents();
}));
it('...', () => {
let fixture = TestBed.createComponent(AppComponent);
});另请参阅
https://stackoverflow.com/questions/39888701
复制相似问题