【发布时间】:2017-02-27 15:24:53
【问题描述】:
我正在使用 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() 找到要监视的对象
【问题讨论】:
标签: javascript angular typescript jasmine angular2-testing