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

Commit 3da5b53

Browse files
committed
fix(ngResource): canceling XHR request using promise - refactor
1 parent 2955bbf commit 3da5b53

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/ngResource/resource.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,17 @@ angular.module('ngResource', ['ng']).
568568
undefined;
569569

570570
forEach(action, function(value, key) {
571-
if (key != 'params' && key != 'isArray' && key != 'interceptor' && key != 'timeout') {
572-
httpConfig[key] = copy(value);
573-
} else if (key == 'timeout') {
574-
httpConfig[key] = value;
571+
switch (key) {
572+
default:
573+
httpConfig[key] = copy(value);
574+
break;
575+
case 'params':
576+
case 'isArray':
577+
case 'interceptor':
578+
break;
579+
case 'timeout':
580+
httpConfig[key] = value;
581+
break;
575582
}
576583
});
577584

test/ngResource/resourceSpec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ describe('resource', function() {
13571357
);
13581358
});
13591359

1360-
it('If timeout promise is resolved, cancel the request', function() {
1360+
it('should cancel the request if timeout promise is resolved', function() {
13611361
var canceler = $q.defer();
13621362

13631363
$httpBackend.when('GET', '/CreditCard').respond({data: '123'});
@@ -1372,7 +1372,7 @@ describe('resource', function() {
13721372
CreditCard.query();
13731373

13741374
canceler.resolve();
1375-
expect(function() { $httpBackend.flush();}).toThrow(new Error("No pending request to flush !"));
1375+
expect($httpBackend.flush).toThrow(new Error("No pending request to flush !"));
13761376

13771377
canceler = $q.defer();
13781378
CreditCard = $resource('/CreditCard', {}, {
@@ -1383,9 +1383,7 @@ describe('resource', function() {
13831383
});
13841384

13851385
CreditCard.query();
1386-
expect(function() { $httpBackend.flush();}).not.toThrow(new Error("No pending request to flush !"));
1387-
1388-
1386+
expect($httpBackend.flush).not.toThrow();
13891387
});
13901388

13911389

0 commit comments

Comments
 (0)