title: Test angular app which does an ajax request on startup
body: <p>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:</p>
  
  <pre><code>Error: Unexpected request: GET /foo
  No more request expected
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>beforeEach(inject(function ($httpBackend) {
      $httpBackend.expectGET("/foo").respond("bar");
  }));
  </code></pre>
  
  <p>so I can do expectations on requests.</p>
  
  <p>The Problem is that it seems like I cannot initialize my $httpBackend and load my module/app after that like shown here:</p>
  
  <pre><code>beforeEach(inject(function ($httpBackend) {
      $httpBackend.expectGET("/foo").respond("bar");
  }));
  beforeEach(module('myApplication'));
  </code></pre>
  
  <p>It fails with</p>
  
  <pre><code>Error: Injector already created, can not register a module!
  </code></pre>
  
  <p>But to load my module/app first and configure the $httpBackend after this it is too late:</p>
  
  <pre><code>beforeEach(module('myApplication'));
  beforeEach(inject(function ($httpBackend) {
      $httpBackend.expectGET("/foo").respond("bar");
  }));
  </code></pre>
  
  <p>fails with</p>
  
  <pre><code>Error: Unexpected request: GET /foo
  No more request expected
  </code></pre>
  
  <p>it fails because I need to make an ajax request inside of my application configuration <code>myapp.config(function(...) {.. doSomeAjax  ..}</code></p>
  
  <p>Any Idea how to solve the Problem?</p>