MockConnection
Mock Connection to represent a Connection
for tests.
Deprecated: see https://angular.io/guide/http
class MockConnection implements Connection {
constructor(req: Request)
readyState: ReadyState
request: Request
response: ReplaySubject<Response>
mockRespond(res: Response)
mockDownload(res: Response)
mockError(err?: Error)
}
Constructor
Parameters
|
Properties
Property | Description |
---|---|
readyState: ReadyState
|
Describes the state of the connection, based on |
request: Request
|
Request
instance used to create the connection. |
response: ReplaySubject<Response>
|
EventEmitter
of |
Methods
Sends a mock response to the connection. This response is the value that is emitted to the
|
||
Parameters
|
Not yet implemented! |
||
Parameters
|
||
Sends the provided |
Emits the provided error object as an error to the |
||
Parameters
|
Usage notes
Example of mockRespond()
var connection;
backend.connections.subscribe(c => connection = c);
http.request('data.json').subscribe(res => console.log(res.text()));
connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
'fake response'
Example of mockError()
var connection;
backend.connections.subscribe(c => connection = c);
http.request('data.json').subscribe(res => res, err => console.log(err)));
connection.mockError(new Error('error'));