From 9f4f5937112655a9881d3281da8e72035bc8b180 Mon Sep 17 00:00:00 2001 From: David Bennett Date: Sat, 27 Apr 2013 11:22:03 -0400 Subject: feat($http): add support for aborting via timeout promises If the timeout argument is a promise, abort the request when it is resolved. Implemented by adding support to $httpBackend service and $httpBackend mock service. This api can also be used to explicitly abort requests while keeping the communication between the deffered and promise unidirectional. Closes #1159 --- test/ng/httpSpec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/ng/httpSpec.js') diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 5984106c..4ddb3661 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -1273,6 +1273,33 @@ describe('$http', function() { }); + describe('timeout', function() { + + it('should abort requests when timeout promise resolves', inject(function($q) { + var canceler = $q.defer(); + + $httpBackend.expect('GET', '/some').respond(200); + + $http({method: 'GET', url: '/some', timeout: canceler.promise}).error( + function(data, status, headers, config) { + expect(data).toBeUndefined(); + expect(status).toBe(0); + expect(headers()).toEqual({}); + expect(config.url).toBe('/some'); + callback(); + }); + + $rootScope.$apply(function() { + canceler.resolve(); + }); + + expect(callback).toHaveBeenCalled(); + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + })); + }); + + describe('pendingRequests', function() { it('should be an array of pending requests', function() { -- cgit v1.2.3