title: Unit test when loading things at app run with AngularJS
body: <p>I need my app to run some configuration at runtime vi an HTTP endpoint.</p>
  
  <p>I wrote a simple service to do that:</p>
  
  <pre><code>module.factory('config', function ($http, analytics) {
      return {
          load: function () {
              $http.get('/config').then(function (response) {
                  analytics.setAccount(response.googleAnalyticsAccount);
              });
          }
      }
  });
  </code></pre>
  
  <p>Next, I call this module in a run block of my app module:</p>
  
  <pre><code>angular.module('app').***.run(function(config) {
          config.load();
      });
  </code></pre>
  
  <p>All is working well when the app is running but in my unit tests, I get this error: "Error: Unexpected request: GET /config"</p>
  
  <p>I know what it means but I don't know how to mock it when it happens from a run block.</p>
  
  <p>Thanks for your help</p>
  
  <p><strong>EDIT to add spec</strong></p>
  
  <p>Calling this before each</p>
  
  <pre><code>beforeEach(angular.mock.module('app'));
  </code></pre>
  
  <p>Tried this to mock $httpBackend:</p>
  
  <pre><code>beforeEach(inject(function($httpBackend) {
  
      $httpBackend.expectGET('/config').respond(200, {'googleAnalyticsAccount':});
  
      angular.mock.module('app')
  
      $httpBackend.flush();
  }));
  </code></pre>
  
  <p>But got:</p>
  
  <pre><code>TypeError: Cannot read property 'stack' of null
          at workFn (/Users/arnaud/workspace/unishared-dredit/test/lib/angular/angular-mocks.js:1756:55)
      TypeError: Cannot read property 'stack' of null
          at workFn (/Users/arnaud/workspace/unishared-dredit/test/lib/angular/angular-mocks.js:1756:55)
      TypeError: Cannot read property 'stack' of null
          at workFn (/Users/arnaud/workspace/unishared-dredit/test/lib/angular/angular-mocks.js:1756:55)
  </code></pre>
  
  <p><strong>EDIT since update to AngularJS 1.0.6</strong></p>
  
  <p>Since I've updated to AngularJS 1.0.6, advised by Igor from the Angular team, the issue is gone but now I've now got this one, which sounds more "normal" but I still can't figure out how to make it works.</p>
  
  <pre><code>Error: Injector already created, can not register a module!
  </code></pre>