ngMockE2E.$httpBackend.when()

when(method, url, [data], [headers], [keys]);

Creates a new backend definition.

Parameters

Param Type Details
method string

HTTP method.

url stringRegExpfunction(string)

HTTP url or function that receives a url and returns true if the url matches the current definition.

data
(optional)
stringRegExp

HTTP request body.

headers
(optional)
Objectfunction(Object)

HTTP headers or function that receives http header object and returns true if the headers match the current definition.

keys
(optional)
Array

Array of keys to assign to regex matches in request url described on $httpBackend mock.

Returns

requestHandler

Returns an object with respond and passThrough methods that control how a matched request is handled. You can save this object for later use and invoke respond or passThrough again in order to change how a matched request is handled.

  • respond â {function([status,] data[, headers, statusText]) | function(function(method, url, data, headers, params)} â The respond method takes a set of static data to be returned or a function that can return an array containing response status (number), response data (string), response headers (Object), and the text for the status (string).
  • passThrough â {function()} â Any request matching a backend definition with passThrough handler will be passed through to the real backend (an XHR request will be made to the server.)
  • Both methods return the requestHandler object for possible overrides.
doc_AngularJS
2016-03-29 16:12:10
Comments
Leave a Comment

Please login to continue.