MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / $httpBackend

Function $httpBackend

lib/test/angular/1.6.7/angular-mocks.js:1370–1458  ·  view source on GitHub ↗
(method, url, data, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers)

Source from the content-addressed store, hash-verified

1368
1369 // TODO(vojta): change params to: method, url, data, headers, callback
1370 function $httpBackend(method, url, data, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers) {
1371
1372 var xhr = new MockXhr(),
1373 expectation = expectations[0],
1374 wasExpected = false;
1375
1376 xhr.$$events = eventHandlers;
1377 xhr.upload.$$events = uploadEventHandlers;
1378
1379 function prettyPrint(data) {
1380 return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp)
1381 ? data
1382 : angular.toJson(data);
1383 }
1384
1385 function wrapResponse(wrapped) {
1386 if (!$browser && timeout) {
1387 if (timeout.then) {
1388 timeout.then(handleTimeout);
1389 } else {
1390 $timeout(handleTimeout, timeout);
1391 }
1392 }
1393
1394 handleResponse.description = method + ' ' + url;
1395 return handleResponse;
1396
1397 function handleResponse() {
1398 var response = wrapped.response(method, url, data, headers, wrapped.params(url));
1399 xhr.$$respHeaders = response[2];
1400 callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(),
1401 copy(response[3] || ''), copy(response[4]));
1402 }
1403
1404 function handleTimeout() {
1405 for (var i = 0, ii = responses.length; i < ii; i++) {
1406 if (responses[i] === handleResponse) {
1407 responses.splice(i, 1);
1408 callback(-1, undefined, '', undefined, 'timeout');
1409 break;
1410 }
1411 }
1412 }
1413 }
1414
1415 if (expectation && expectation.match(method, url)) {
1416 if (!expectation.matchData(data)) {
1417 throw new Error('Expected ' + expectation + ' with different data\n' +
1418 'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data);
1419 }
1420
1421 if (!expectation.matchHeaders(headers)) {
1422 throw new Error('Expected ' + expectation + ' with different headers\n' +
1423 'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' +
1424 prettyPrint(headers));
1425 }
1426
1427 expectations.shift();

Callers 1

sendReqFunction · 0.70

Calls 2

prettyPrintFunction · 0.70
wrapResponseFunction · 0.70

Tested by

no test coverage detected