MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / $httpBackend

Function $httpBackend

lib/test/angular/1.4.3/angular-mocks.js:1139–1212  ·  view source on GitHub ↗
(method, url, data, callback, headers, timeout, withCredentials)

Source from the content-addressed store, hash-verified

1137
1138 // TODO(vojta): change params to: method, url, data, headers, callback
1139 function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1140 var xhr = new MockXhr(),
1141 expectation = expectations[0],
1142 wasExpected = false;
1143
1144 function prettyPrint(data) {
1145 return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp)
1146 ? data
1147 : angular.toJson(data);
1148 }
1149
1150 function wrapResponse(wrapped) {
1151 if (!$browser && timeout) {
1152 timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout);
1153 }
1154
1155 return handleResponse;
1156
1157 function handleResponse() {
1158 var response = wrapped.response(method, url, data, headers);
1159 xhr.$$respHeaders = response[2];
1160 callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(),
1161 copy(response[3] || ''));
1162 }
1163
1164 function handleTimeout() {
1165 for (var i = 0, ii = responses.length; i < ii; i++) {
1166 if (responses[i] === handleResponse) {
1167 responses.splice(i, 1);
1168 callback(-1, undefined, '');
1169 break;
1170 }
1171 }
1172 }
1173 }
1174
1175 if (expectation && expectation.match(method, url)) {
1176 if (!expectation.matchData(data)) {
1177 throw new Error('Expected ' + expectation + ' with different data\n' +
1178 'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data);
1179 }
1180
1181 if (!expectation.matchHeaders(headers)) {
1182 throw new Error('Expected ' + expectation + ' with different headers\n' +
1183 'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' +
1184 prettyPrint(headers));
1185 }
1186
1187 expectations.shift();
1188
1189 if (expectation.response) {
1190 responses.push(wrapResponse(expectation));
1191 return;
1192 }
1193 wasExpected = true;
1194 }
1195
1196 var i = -1, definition;

Callers 1

sendReqFunction · 0.70

Calls 2

prettyPrintFunction · 0.70
wrapResponseFunction · 0.70

Tested by

no test coverage detected