p.location-badge.
exported from angular2/http
defined in angular2/src/http/backends/mock_backend.ts (line 8)
:markdown
Mock Connection to represent a Connection
for tests.
.l-main-section
h2 Annotations
.l-sub-section
h3.annotation IMPLEMENTS
pre.prettyprint
code.
@IMPLEMENTS(Connection)
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
constructor(req: Request)
:markdown
.l-sub-section
h3 readyState
:markdown
Describes the state of the connection, based on `XMLHttpRequest.readyState`, but with
additional states. For example, state 5 indicates an aborted connection.
.l-sub-section
h3 request
:markdown
Request
instance used to create the connection.
.l-sub-section
h3 response
:markdown
EventEmitter
of Response
. Can be subscribed to in order to be notified when a
response is available.
.l-sub-section
h3 dispose
pre.prettyprint
code.
dispose()
:markdown
Changes the `readyState` of the connection to a custom state of 5 (cancelled).
.l-sub-section
h3 mockRespond
pre.prettyprint
code.
mockRespond(res: Response)
:markdown
Sends a mock response to the connection. This response is the value that is emitted to the
EventEmitter
returned by Http
.
#Example
```
var connection;
backend.connections.subscribe(c => connection = c);
http.request('data.json').subscribe(res => console.log(res.text()));
connection.mockRespond(new Response('fake response')); //logs 'fake response'
```
.l-sub-section
h3 mockDownload
pre.prettyprint
code.
mockDownload(res: Response)
:markdown
Not yet implemented!
Sends the provided Response
to the `downloadObserver` of the `Request`
associated with this connection.
.l-sub-section
h3 mockError
pre.prettyprint
code.
mockError(err?: Error)
:markdown
Emits the provided error object as an error to the Response
EventEmitter
returned
from Http
.