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/ngMock/angular-mocksSpec.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/ngMock/angular-mocksSpec.js') diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 176c5c92..220f8e58 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -798,6 +798,24 @@ describe('ngMock', function() { }); + it('should abort requests when timeout promise resolves', function() { + hb.expect('GET', '/url1').respond(200); + + var canceler, then = jasmine.createSpy('then').andCallFake(function(fn) { + canceler = fn; + }); + + hb('GET', '/url1', null, callback, null, {then: then}); + expect(typeof canceler).toBe('function'); + + canceler(); // simulate promise resolution + + expect(callback).toHaveBeenCalledWith(-1, undefined, ''); + hb.verifyNoOutstandingExpectation(); + hb.verifyNoOutstandingRequest(); + }); + + it('should throw an exception if no response defined', function() { hb.when('GET', '/test'); expect(function() { @@ -1006,8 +1024,8 @@ describe('ngMockE2E', function() { hb.when('GET', /\/passThrough\/.*/).passThrough(); hb('GET', '/passThrough/23', null, callback); - expect(realHttpBackend). - toHaveBeenCalledOnceWith('GET', '/passThrough/23', null, callback, undefined); + expect(realHttpBackend).toHaveBeenCalledOnceWith( + 'GET', '/passThrough/23', null, callback, undefined, undefined); }); }); -- cgit v1.2.3