Testing code calling external HTTP services is often problematic due to network latency and changing data. We want our test to run fast and be predictable. Fortunately, AngularJS provides excellent mocks to simulate HTTP responses.
In AngularJS the
$http service depends on another, lower-level service
$httpBackend. We can think of the
$httpBackend as a thin wrapper over the
XMLHttpRequest object. This wrapper masks browsers incompatibilities and enables JSONP requests.
Application code should never call the
$httpBackend directly as the
$http service provides a much better abstraction. But having a separate
$httpBackend service means that we can swap it for a mock one during testing.
To see the