我刺探我的组件的这样一个方法:我如何验证一个方法被调用n次?
spyOn(component, 'someMethod');
我如何验证component.someMethod被称为n次?
Intelisense没有给我calls
属性。
我刺探我的组件的这样一个方法:我如何验证一个方法被调用n次?
spyOn(component, 'someMethod');
我如何验证component.someMethod被称为n次?
Intelisense没有给我calls
属性。
it("tracks the number of times it was called", function() {
spyOn(foo, 'setBar');
expect(foo.setBar.calls.count()).toEqual(0);
foo.setBar();
foo.setBar();
expect(foo.setBar.calls.count()).toEqual(2);
});
您不需要任何自定义方法。茉莉花确实提供方法toHaveBeenCalledTimes()
请参阅茉莉花文档。
https://jasmine.github.io/2.4/introduction.html
你比如这将是 - 预期(component.yourmethod).toHaveBeenCalledTimes(N);
仅有代码的答案通常不会自行工作 - 请添加一个解释,说明如何帮助解决问题 – Mikkel