148 lines
2.9 KiB
Plaintext
148 lines
2.9 KiB
Plaintext
|
|
p.location-badge.
|
|
exported from <a href='../http'>angular2/http</a>
|
|
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/http/backends/mock_backend.ts#L8-L98">angular2/src/http/backends/mock_backend.ts (line 8)</a>
|
|
|
|
:markdown
|
|
Mock Connection to represent a <a href='Connection-class.html'><code>Connection</code></a> for tests.
|
|
|
|
|
|
.l-main-section
|
|
h2 Members
|
|
.l-sub-section
|
|
h3#constructor constructor
|
|
|
|
|
|
pre.prettyprint
|
|
code.
|
|
constructor(req: Request)
|
|
|
|
:markdown
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#readyState 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 request
|
|
|
|
|
|
:markdown
|
|
<a href='Request-class.html'><code>Request</code></a> instance used to create the connection.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#response response
|
|
|
|
|
|
:markdown
|
|
<a href='../core/EventEmitter-class.html'><code>EventEmitter</code></a> of <a href='Response-class.html'><code>Response</code></a>. Can be subscribed to in order to be notified when a
|
|
response is available.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#dispose dispose
|
|
|
|
|
|
pre.prettyprint
|
|
code.
|
|
dispose()
|
|
|
|
:markdown
|
|
Changes the `readyState` of the connection to a custom state of 5 (cancelled).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#mockRespond 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
|
|
<a href='../core/EventEmitter-class.html'><code>EventEmitter</code></a> returned by <a href='Http-class.html'><code>Http</code></a>.
|
|
|
|
#Example
|
|
|
|
```
|
|
var connection;
|
|
backend.connections.toRx().subscribe(c => connection = c);
|
|
http.request('data.json').toRx().subscribe(res => console.log(res.text()));
|
|
connection.mockRespond(new Response('fake response')); //logs 'fake response'
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#mockDownload mockDownload
|
|
|
|
|
|
pre.prettyprint
|
|
code.
|
|
mockDownload(res: Response)
|
|
|
|
:markdown
|
|
Not yet implemented!
|
|
|
|
Sends the provided <a href='Response-class.html'><code>Response</code></a> to the `downloadObserver` of the `Request`
|
|
associated with this connection.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.l-sub-section
|
|
h3#mockError mockError
|
|
|
|
|
|
pre.prettyprint
|
|
code.
|
|
mockError(err?: Error)
|
|
|
|
:markdown
|
|
Emits the provided error object as an error to the <a href='Response-class.html'><code>Response</code></a> <a href='../core/EventEmitter-class.html'><code>EventEmitter</code></a>
|
|
returned
|
|
from <a href='Http-class.html'><code>Http</code></a>.
|
|
|
|
|
|
|
|
|
|
|
|
|