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

Commit 947cb4d

Browse files
biohazardpb4gkalpak
biohazardpb4
authored andcommitted
fix(ngMockE2E): pass responseType to $delegate when using passThrough
The `ngMockE2E` `$httpBackend` has a mechanism to allow requests to pass through, if one wants to send a real HTTP request instead of mocking. The specified `responseType` of the request was never passed through to the "real" `$httpBackend` (of the `ng` module), resulting in it being effectively ignored. Fixes #5415 Closes #5783
1 parent 77fc41f commit 947cb4d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/ngMock/angular-mocks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,8 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
12411241
}
12421242

12431243
// TODO(vojta): change params to: method, url, data, headers, callback
1244-
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1244+
function $httpBackend(method, url, data, callback, headers, timeout, withCredentials, responseType) {
1245+
12451246
var xhr = new MockXhr(),
12461247
expectation = expectations[0],
12471248
wasExpected = false;
@@ -1305,7 +1306,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
13051306
// if $browser specified, we do auto flush all requests
13061307
($browser ? $browser.defer : responsesPush)(wrapResponse(definition));
13071308
} else if (definition.passThrough) {
1308-
$delegate(method, url, data, callback, headers, timeout, withCredentials);
1309+
$delegate(method, url, data, callback, headers, timeout, withCredentials, responseType);
13091310
} else throw new Error('No response defined !');
13101311
return;
13111312
}

test/ngMock/angular-mocksSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,10 +1794,10 @@ describe('ngMockE2E', function() {
17941794
describe('passThrough()', function() {
17951795
it('should delegate requests to the real backend when passThrough is invoked', function() {
17961796
hb.when('GET', /\/passThrough\/.*/).passThrough();
1797-
hb('GET', '/passThrough/23', null, callback, {}, null, true);
1797+
hb('GET', '/passThrough/23', null, callback, {}, null, true, 'blob');
17981798

17991799
expect(realHttpBackend).toHaveBeenCalledOnceWith(
1800-
'GET', '/passThrough/23', null, callback, {}, null, true);
1800+
'GET', '/passThrough/23', null, callback, {}, null, true, 'blob');
18011801
});
18021802

18031803
it('should be able to override a respond definition with passThrough', function() {
@@ -1806,7 +1806,7 @@ describe('ngMockE2E', function() {
18061806
hb('GET', '/passThrough/23', null, callback, {}, null, true);
18071807

18081808
expect(realHttpBackend).toHaveBeenCalledOnceWith(
1809-
'GET', '/passThrough/23', null, callback, {}, null, true);
1809+
'GET', '/passThrough/23', null, callback, {}, null, true, undefined);
18101810
});
18111811

18121812
it('should be able to override a respond definition with passThrough', inject(function($browser) {

0 commit comments

Comments
 (0)