For such scenarios, I often use the Jasmine spyOn () function. You can track the functions of $http , $resource or a custom service (for example, myServiceThatUsesHTTP below):
spyOn(myServiceThatUsesHTTP, 'query'); // test, then verify: expect(myServiceThatUsesHTTP.query).not.toHaveBeenCalled(); // or expect(myServiceThatUsesHTTP.query.callCount).toBe(0);
When you spyOn() execute a function, the original function is replaced. The code for the original function is not executed, which can be good or bad (depending on what you need to do for the test).
For example, if you need the $promise object returned by $ http or $ resource, you can do this:
spyOn($http, '$get').andCallThrough();
source share