AngularJS Flashcards
$httpBackend
Used to mock the $http service in unit tests. As $httpBackend responds to requests asynchronously, we need to call $httpBackend.flush() at the end of every test to clear the execution environment.
Methods:
Expect - creates expectation that a particular request will be made, and allows us to define a response.
When - mocks backend functionality. Allows us to return a precanned response, but without setting an expectation.
Include $httpBackend.verifyNoOutstandingExpectation(), and $httpBackend.verifyNoOutstandingRequest() in afterEach
Promise
An interface for interacting with an object that represents the result of an action performed asynchronously. Utilize the promise chaining pattern to apply as many transformation as you need. As long as the promise object is returned, you can keep chaining.
$http transformResponse
For any modification on the result of an $http request, before passing data to the .then() method of a promise chain.