how to verify that none of http request method are invoked to do any request. I have this code :
$scope.getSubnetsPageDetails = function (pageNumber) {
$http.get(URLS.subnetsPagesCount(pageNumber)).success(function (response) {
$scope.pageDetails = response;
}).error(function (response, errorCode) {
});
};
and this test :
it("should not allow request with negative page number", function () {
scope.getSubnetsPageDetails(-1);
//verify that htt.get is not invoked at all
});
How to verify that http.get is not invoked ?
You can test that no calls are made by using the
verifyNoOutstandingRequest()method from the $httpBackend mock.Usually those kind of verification is done in the
afterEachsection of a Jasmine’s tests. On top of this it is common to call another method,verifyNoOutstandingExpectation()to verify that all the expected calls were actually invoked.Here is the code, where you need to inject the
$httpBackendmock:then do you test and at the end:
Of course you could invoke the
$httpBackend.verifyNoOutstandingRequest()inside an individual test. The mentioned http://docs.angularjs.org/api/ngMock.$httpBackend page has a wealth of information on the topic.