diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 742d7aa86a85..1a262b9cb8b6 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -126,7 +126,9 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc function completeRequest(callback, status, response, headersString, statusText) { // cancel timeout and subsequent timeout promise resolution - timeoutId && $browserDefer.cancel(timeoutId); + if (timeoutId !== void 0) { + $browserDefer.cancel(timeoutId); + } jsonpDone = xhr = null; callback(status, response, headersString, statusText); diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 2c1da6eba4bb..9b3116932d49 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -103,6 +103,19 @@ describe('$httpBackend', function() { }); + it('should cancel timeout on completeRequest()', function() { + fakeTimeout.ids.length = fakeTimeout.fns.length = fakeTimeout.delays.length = 0; + fakeTimeoutId = 0; + spyOn(fakeTimeout, 'cancel').andCallThrough(); + $backend('GET', '/some-url', null, callback, void 0, 100); + xhr = MockXhr.$$lastInstance; + expect(fakeTimeout.cancel).not.toHaveBeenCalled(); + xhr.status = 200; + xhr.onload(); + expect(fakeTimeout.cancel).toHaveBeenCalledWith(1); + }); + + it('should normalize IE\'s 1223 status code into 204', function() { callback.andCallFake(function(status) { expect(status).toBe(204);