I need test components of my angular app. The Problem is every time I want to test something the karma testrunner shows me that error:
Error: Unexpected request: GET /foo
No more request expected
After some research it was clear that the test framework blocks all requests and I need to declare every request accepted in my test via:
beforeEach(inject(function ($httpBackend) {
$httpBackend.expectGET("/foo").respond("bar");
}));
so I can do expectations on requests.
The Problem is that it seems like I cannot initialize my $httpBackend and load my module/app after that like shown here:
beforeEach(inject(function ($httpBackend) {
$httpBackend.expectGET("/foo").respond("bar");
}));
beforeEach(module('myApplication'));
It fails with
Error: Injector already created, can not register a module!
But to load my module/app first and configure the $httpBackend after this it is too late:
beforeEach(module('myApplication'));
beforeEach(inject(function ($httpBackend) {
$httpBackend.expectGET("/foo").respond("bar");
}));
fails with
Error: Unexpected request: GET /foo
No more request expected
it fails because I need to make an ajax request inside of my application configuration myapp.config(function(...) {.. doSomeAjax ..}
Any Idea how to solve the Problem?