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

Commit 86fcb95

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

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/ngMock/angular-mocks.js

100644100755
+4-2
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,8 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
11021102
}
11031103

11041104
// TODO(vojta): change params to: method, url, data, headers, callback
1105-
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1105+
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials,
1106+
progressCallback) {
11061107
var xhr = new MockXhr(),
11071108
expectation = expectations[0],
11081109
wasExpected = false;
@@ -1162,7 +1163,8 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
11621163
// if $browser specified, we do auto flush all requests
11631164
($browser ? $browser.defer : responsesPush)(wrapResponse(definition));
11641165
} else if (definition.passThrough) {
1165-
$delegate(method, url, data, callback, headers, timeout, withCredentials);
1166+
$delegate(method, url, data, callback, headers, timeout, withCredentials,
1167+
progressCallback);
11661168
} else throw new Error('No response defined !');
11671169
return;
11681170
}

test/ng/httpBackendSpec.js

100644100755
+19
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,25 @@ describe('$httpBackend', function() {
312312
expect(MockXhr.$$lastInstance.withCredentials).toBe(true);
313313
});
314314

315+
describe('upload and download events', function() {
316+
317+
it('should call progress callback on POST requests', function() {
318+
$backend('POST', '/whatever', null, noop, {}, null, null, 'blob', callback);
319+
320+
MockXhr.$$lastInstance.onprogress();
321+
322+
expect(callback).toHaveBeenCalled();
323+
});
324+
325+
it('should call progress callback on GET requests', function() {
326+
$backend('GET', '/whatever', null, noop, {}, null, null, 'blob', callback);
327+
328+
MockXhr.$$lastInstance.onprogress();
329+
330+
expect(callback).toHaveBeenCalled();
331+
});
332+
});
333+
315334

316335
describe('responseType', function() {
317336

test/ngMock/angular-mocksSpec.js

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1547,10 +1547,10 @@ describe('ngMockE2E', function() {
15471547
describe('passThrough()', function() {
15481548
it('should delegate requests to the real backend when passThrough is invoked', function() {
15491549
hb.when('GET', /\/passThrough\/.*/).passThrough();
1550-
hb('GET', '/passThrough/23', null, callback, {}, null, true);
1550+
hb('GET', '/passThrough/23', null, callback, {}, null, true, null);
15511551

15521552
expect(realHttpBackend).toHaveBeenCalledOnceWith(
1553-
'GET', '/passThrough/23', null, callback, {}, null, true);
1553+
'GET', '/passThrough/23', null, callback, {}, null, true, null);
15541554
});
15551555
});
15561556

0 commit comments

Comments
 (0)