Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 009ebec

Browse files
chirag64gkalpak
authored andcommitted
fix($resource): do not throw when calling old $cancelRequest()
Closes #16037
1 parent 9256dbc commit 009ebec

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/ngResource/resource.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,9 @@ angular.module('ngResource', ['ng']).
830830

831831
function cancelRequest(value) {
832832
promise.catch(noop);
833-
timeoutDeferred.resolve(value);
833+
if (timeoutDeferred !== null) {
834+
timeoutDeferred.resolve(value);
835+
}
834836
}
835837
};
836838

test/ngResource/resourceSpec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,25 @@ describe('cancelling requests', function() {
21022102

21032103
expect(creditCard.$cancelRequest).toBe(noop);
21042104
});
2105+
2106+
it('should not break when calling old `$cancelRequest` after the response arrives', function() {
2107+
$httpBackend.whenGET('/CreditCard').respond({});
2108+
2109+
var CreditCard = $resource('/CreditCard', {}, {
2110+
get: {
2111+
method: 'GET',
2112+
cancellable: true
2113+
}
2114+
});
2115+
2116+
var creditCard = CreditCard.get();
2117+
var cancelRequest = creditCard.$cancelRequest;
2118+
2119+
$httpBackend.flush();
2120+
2121+
expect(cancelRequest).not.toBe(noop);
2122+
expect(cancelRequest).not.toThrow();
2123+
});
21052124
});
21062125

21072126
describe('configuring `cancellable` on the provider', function() {

0 commit comments

Comments
 (0)