How do I test my API backend using AngularJS/karma/jasmine tests?
I have tried to create the smallest test-case showing my error:
The mentioned testing stack is not intended for use this way. The request never gets dispatched because of the $httpMockBackend
that has been decorated on top of your original $httpBackend
.
To allow requests to pass trough you either need to exclude angular-mocks.js
, or specify that some urls should pass through like this:
angular.module('yourModule').run(function ($httpBackend) {
$httpBackend.whenGET(/.*/).passThrough();
}
Read the documentation for $httpMockBackend
here
Also, your test is synchronous, and the server response is asyncronous, so it will not work as expected.