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

Function $httpBackend

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

Source from the content-addressed store, hash-verified

1517
1518 // TODO(vojta): change params to: method, url, data, headers, callback
1519 function $httpBackend(method, url, data, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers) {
1520
1521 var xhr = new MockXhr(),
1522 expectation = expectations[0],
1523 wasExpected = false;
1524
1525 xhr.$$events = eventHandlers;
1526 xhr.upload.$$events = uploadEventHandlers;
1527
1528 function prettyPrint(data) {
1529 return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp)
1530 ? data
1531 : angular.toJson(data);
1532 }
1533
1534 function wrapResponse(wrapped) {
1535 if (!$browser && timeout) {
1536 if (timeout.then) {
1537 timeout.then(function() {
1538 handlePrematureEnd(angular.isDefined(timeout.$$timeoutId) ? 'timeout' : 'abort');
1539 });
1540 } else {
1541 $timeout(function() {
1542 handlePrematureEnd('timeout');
1543 }, timeout);
1544 }
1545 }
1546
1547 handleResponse.description = method + ' ' + url;
1548 return handleResponse;
1549
1550 function handleResponse() {
1551 var response = wrapped.response(method, url, data, headers, wrapped.params(url));
1552 xhr.$$respHeaders = response[2];
1553 callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(),
1554 copy(response[3] || ''), copy(response[4]));
1555 }
1556
1557 function handlePrematureEnd(reason) {
1558 for (var i = 0, ii = responses.length; i < ii; i++) {
1559 if (responses[i] === handleResponse) {
1560 responses.splice(i, 1);
1561 callback(-1, undefined, '', undefined, reason);
1562 break;
1563 }
1564 }
1565 }
1566 }
1567
1568 function createFatalError(message) {
1569 var error = new Error(message);
1570 // In addition to being converted to a rejection, these errors also need to be passed to
1571 // the $exceptionHandler and be rethrown (so that the test fails).
1572 error.$$passToExceptionHandler = true;
1573 return error;
1574 }
1575
1576 if (expectation && expectation.match(method, url)) {

Callers 1

sendReqFunction · 0.70

Calls 3

createFatalErrorFunction · 0.85
prettyPrintFunction · 0.70
wrapResponseFunction · 0.70

Tested by

no test coverage detected