fix($resource): do not throw when calling old $cancelRequest()

Closes #16037
This commit is contained in:
Chirag Bhatia
2017-07-16 00:37:48 +05:30
committed by Georgios Kalpakas
parent ac57a25cd9
commit 01d6a47e91
2 changed files with 22 additions and 1 deletions
+3 -1
View File
@@ -830,7 +830,9 @@ angular.module('ngResource', ['ng']).
function cancelRequest(value) {
promise.catch(noop);
timeoutDeferred.resolve(value);
if (timeoutDeferred !== null) {
timeoutDeferred.resolve(value);
}
}
};
+19
View File
@@ -2102,6 +2102,25 @@ describe('cancelling requests', function() {
expect(creditCard.$cancelRequest).toBe(noop);
});
it('should not break when calling old `$cancelRequest` after the response arrives', function() {
$httpBackend.whenGET('/CreditCard').respond({});
var CreditCard = $resource('/CreditCard', {}, {
get: {
method: 'GET',
cancellable: true
}
});
var creditCard = CreditCard.get();
var cancelRequest = creditCard.$cancelRequest;
$httpBackend.flush();
expect(cancelRequest).not.toBe(noop);
expect(cancelRequest).not.toThrow();
});
});
describe('configuring `cancellable` on the provider', function() {