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

Commit ed51114

Browse files
committed
feat($http): upload and download event - added httpBackend tests
1 parent ca22db9 commit ed51114

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/ng/http.js

100755100644
File mode changed.

src/ng/httpBackend.js

100755100644
File mode changed.

src/ngMock/angular-mocks.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,8 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
11471147
}
11481148

11491149
// TODO(vojta): change params to: method, url, data, headers, callback
1150-
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1150+
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials,
1151+
progressCallback) {
11511152
var xhr = new MockXhr(),
11521153
expectation = expectations[0],
11531154
wasExpected = false;
@@ -1209,7 +1210,8 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
12091210
// if $browser specified, we do auto flush all requests
12101211
($browser ? $browser.defer : responsesPush)(wrapResponse(definition));
12111212
} else if (definition.passThrough) {
1212-
$delegate(method, url, data, callback, headers, timeout, withCredentials);
1213+
$delegate(method, url, data, callback, headers, timeout, withCredentials,
1214+
progressCallback);
12131215
} else throw new Error('No response defined !');
12141216
return;
12151217
}

test/ng/httpBackendSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,25 @@ describe('$httpBackend', function() {
214214
expect(MockXhr.$$lastInstance.withCredentials).toBe(true);
215215
});
216216

217+
describe('upload and download events', function() {
218+
219+
it('should call progress callback on POST requests', function() {
220+
$backend('POST', '/whatever', null, noop, {}, null, null, 'blob', callback);
221+
222+
MockXhr.$$lastInstance.onprogress();
223+
224+
expect(callback).toHaveBeenCalled();
225+
});
226+
227+
it('should call progress callback on GET requests', function() {
228+
$backend('GET', '/whatever', null, noop, {}, null, null, 'blob', callback);
229+
230+
MockXhr.$$lastInstance.onprogress();
231+
232+
expect(callback).toHaveBeenCalled();
233+
});
234+
});
235+
217236

218237
describe('responseType', function() {
219238

test/ngMock/angular-mocksSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1741,10 +1741,10 @@ describe('ngMockE2E', function() {
17411741
describe('passThrough()', function() {
17421742
it('should delegate requests to the real backend when passThrough is invoked', function() {
17431743
hb.when('GET', /\/passThrough\/.*/).passThrough();
1744-
hb('GET', '/passThrough/23', null, callback, {}, null, true);
1744+
hb('GET', '/passThrough/23', null, callback, {}, null, true, null);
17451745

17461746
expect(realHttpBackend).toHaveBeenCalledOnceWith(
1747-
'GET', '/passThrough/23', null, callback, {}, null, true);
1747+
'GET', '/passThrough/23', null, callback, {}, null, true, null);
17481748
});
17491749

17501750
it('should be able to override a respond definition with passThrough', function() {

0 commit comments

Comments
 (0)