angular2-http-testing
Makes testing Http calls as easy as were with AngularJS.
Installation
npm install angular2-http-testing --save-dev
Usage
// First add it as a providerbeforeEach; // Get the instance of itbeforeEachinject,; // Use it in a test caseit'should call fake endpoint',
It is possible to specify every detail of the response.
// can be object, it will be json stringified if not a string;;; backend .expectGET'users/blacksonic' .respondresponseBody, responseStatus, responseHeaders;
For requests outside of GET the request body can be also specified.
backend.expectPost 'usernamepassword/login', // url , // payload // headers.respondresponseForm;
Convenience methods available for different kind of requests:
expectGet
, expectPost
, expectDelete
, expectPut
, expectPatch
, expectHead
, expectOptions
.
After the tests run it is possible to check for outstanding connections or expectations that are not addressed.
afterEach;