# angular.mock.service.$browser.xhr

## Description

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`.

## Usage

    $browser.xhr(method, url[, data], callback, headers);

### Parameters

- `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.

### Returns

`{object}` –

Response configuration object. You can call its `respond()` method to configure what should the browser mock return when the response is `flushed`.