我刺探我的組件的這樣一個方法:我如何驗證一個方法被調用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