Mock Connection to represent a Connection for tests.
构造函数 属性 属性名 类型 说明 readyStateReadyState Describes the state of the connection, based on XMLHttpRequest.readyState, but with additional states. For example, state 5 indicates an aborted connection.
requestRequest Requestinstance used to create the connection.
responseReplaySubject<Response >EventEmitterof Response . Can be subscribed to in order to be notified when a response is available.
方法 Sends a mock response to the connection. This response is the value that is emitted to the EventEmitter returned by Http .
mockRespond(res: Response ) 参数 Example 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'
Not yet implemented!
mockDownload(res: Response ) 参数 Sends the provided Response to the downloadObserver of the Request associated with this connection.
Emits the provided error object as an error to the ResponseEventEmitter returned from Http .
mockError(err?: Error) 参数 errType: Error.
可选. 默认值是 undefined.
Example var connection; backend.connections.subscribe(c => connection = c); http.request('data.json').subscribe(res => res, err => console.log(err))); connection.mockError(new Error('error'));