我正在使用 angular-cli 测试框架。
在我的组件中,我使用了“ng2-slim-loading-bar”节点模块。
submit(){
this._slimLoadingBarService.start(() => {
});
//method operations
}
现在,当我测试此组件时,我已将 spyOn 此服务应用为:
beforeEach(() => {
let slimLoadingBarService=new SlimLoadingBarService();
demoComponent = new DemoComponent(slimLoadingBarService);
TestBed.configureTestingModule({
declarations: [
DemoComponent
],
providers: [
{ provide: SlimLoadingBarService, useClass: SlimLoadingBarService}
],
imports: [
SharedModule
]
});
});
it('should pass data to servie', () => {
spyOn(slimLoadingBarService,'start').and.callThrough();
//testing code,if I remove the above service from my component, test runs fine
});
但它不工作。
它抛出以下错误:
spyOn 找不到用于监视 start() 的对象