Reputation: 15714
I'm spying on a method of my component like this :
spyOn(component, 'someMethod');
How can I verify that component.someMethod was called n times ?
Intelisense is not giving me the calls
attribute.
Upvotes: 0
Views: 1827
Reputation: 909
You dont need any custom methods. Jasmine does provide method toHaveBeenCalledTimes()
See the jasmine doc.
https://jasmine.github.io/2.4/introduction.html
for your example it will be - expect(component.yourmethod).toHaveBeenCalledTimes(n);
Upvotes: 3
Reputation: 36
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);
});
Upvotes: 1