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

Commit 1fc383b

Browse files
committed
fix($resource): Check if timeoutDeferred is null inside $cancelRequest
1 parent 529550d commit 1fc383b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/ngResource/resource.js

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

824824
function cancelRequest(value) {
825825
promise.catch(noop);
826-
timeoutDeferred.resolve(value);
826+
if (timeoutDeferred !== null) {
827+
timeoutDeferred.resolve(value);
828+
}
827829
}
828830
};
829831

test/ngResource/resourceSpec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,28 @@ describe('cancelling requests', function() {
21012101

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

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

0 commit comments

Comments
 (0)