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

Commit

Permalink
fix($resource): do not throw when calling old $cancelRequest()
Browse files Browse the repository at this point in the history
Closes #16037
  • Loading branch information
chirag64 authored and gkalpak committed Jul 27, 2017
1 parent 9256dbc commit 009ebec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ngResource/resource.js
Expand Up @@ -830,7 +830,9 @@ angular.module('ngResource', ['ng']).

function cancelRequest(value) {
promise.catch(noop);
timeoutDeferred.resolve(value);
if (timeoutDeferred !== null) {
timeoutDeferred.resolve(value);
}
}
};

Expand Down
19 changes: 19 additions & 0 deletions test/ngResource/resourceSpec.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 009ebec

Please sign in to comment.