Generic method for training browser to expect a request in a test and respond to it.
See also convenience methods for browser training:
$browser.xhr.expectGET
$browser.xhr.expectPOST
$browser.xhr.expectPUT
$browser.xhr.expectDELETE
$browser.xhr.expectJSON
To flush pending requests in tests use
$browser.xhr.flush
.
$browser.xhr(method, url[, data], callback, headers);
method – {string} –
Expected HTTP method.
url – {string} –
Url path for which a request is expected.
data(optional) – {(object|string)} –
Expected body of the (POST) HTTP request.
callback – {function(number, *)} –
Callback to call when response is flushed.
headers – {object} –
Key-value pairs of expected headers.
{object}
– Response configuration object. You can call its respond()
method to
configure what should the browser mock return when the response is
flushed
.