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

Commit db8ec99

Browse files
caitpgyx1000
authored andcommitted
fix($httpBackend): fixup patch for #9979
1 parent 0602103 commit db8ec99

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ng/httpBackend.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
126126

127127
function completeRequest(callback, status, response, headersString, statusText) {
128128
// cancel timeout and subsequent timeout promise resolution
129-
timeoutId !== undefined && $browserDefer.cancel(timeoutId);
129+
if (timeoutId !== void 0) {
130+
$browserDefer.cancel(timeoutId);
131+
}
130132
jsonpDone = xhr = null;
131133

132134
callback(status, response, headersString, statusText);

test/ng/httpBackendSpec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ describe('$httpBackend', function() {
103103
});
104104

105105

106+
it('should cancel timeout on completeRequest()', function() {
107+
fakeTimeout.ids.length = fakeTimeout.fns.length = fakeTimeout.delays.length = 0;
108+
fakeTimeoutId = 0;
109+
spyOn(fakeTimeout, 'cancel').andCallThrough();
110+
$backend('GET', '/some-url', null, callback, void 0, 100);
111+
xhr = MockXhr.$$lastInstance;
112+
expect(fakeTimeout.cancel).not.toHaveBeenCalled();
113+
xhr.status = 200;
114+
xhr.onload();
115+
expect(fakeTimeout.cancel).toHaveBeenCalledWith(1);
116+
});
117+
118+
106119
it('should normalize IE\'s 1223 status code into 204', function() {
107120
callback.andCallFake(function(status) {
108121
expect(status).toBe(204);

0 commit comments

Comments
 (0)