MockXHR

export class MockXHR

exported from angular2/testing defined in angular2/src/compiler/xhr_mock.ts (line 5)

A mock implementation of XHR that allows outgoing requests to be mocked and responded to within a single test, without going to the network.

Members

get(url: string) : Promise<string>

Not Yet Documented

expect(url: string, response: string)

Add an expectation for the given URL. Incoming requests will be checked against the next expectation (in FIFO order). The verifyNoOutstandingExpectations method can be used to check if any expectations have not yet been met.

The response given will be returned if the expectation matches.

when(url: string, response: string)

Add a definition for the given URL to return the given response. Unlike expectations, definitions have no order and will satisfy any matching request at any time. Also unlike expectations, unused definitions do not cause verifyNoOutstandingExpectations to return an error.

flush()

Process pending requests and verify there are no outstanding expectations. Also fails if no requests are pending.

verifyNoOutstandingExpectations()

Throw an exception if any expectations have not been satisfied.