【发布时间】:2018-03-31 13:04:43
【问题描述】:
我是单元测试新手,我的项目中有一个组件,在其构造函数中调用了一个方法
export class myComponent {
constructor(){
this.someMethod();
}
public someMethod(){
//some code
}
我想测试这个方法是否被这个测试套件调用:
it('should call for the someMethod', () => {
spyOn(component, 'someMethod') //also tried .and.callThrough();
expect(component.someMethod).toHaveBeenCalled();;
});
问题是在我的调试过程中,我可以确保调用了该方法,但测试总是会失败。
如果有人提供帮助,将不胜感激。
【问题讨论】:
标签: angularjs typescript ionic-framework ecmascript-6 jasmine