The case for $.post().fail() is giving error in karma test runner. "TypeError: Cannot read property 'fail' of undefined".
How do i write test for $.post().fail()and done().
My angular code is here :
$scope.fetch_data = function (urlbase) {
$.post(urlbase + "/GetBranchMapping", null, function (data) {
$scope.branchInstanceList = data;
$scope.$apply();
$("#divLoading").hide();
}, "json").fail(function (xhr, status, error) {
if (xhr.status == 500) {
$("#divLoading").hide();
alert(error);
}
else if (xhr.status == "403") {
alert("You are not authorized to view this page.");
xhr.status = "0";
}
});
};
And my test case is here :
it("should be able to hide div", function () {
var fakeData = "This will be the new html";
var fakeError="Error";
spyOn($, "ajax").andCallFake(function(params) {
params.success(fakeData);
});
scope.fetch_data('https://localhost/reportingblotter');
expect($('#divLoading').css('display')).toBe('none');
})
Spy for paramas.success() is working, whereas if i used params.fail() its not.
Please help me if anyone has solution.