title: Angular module is executed twice only when testing
body: <p>My angular application is working ok when ran normally, but seems to be executed twice when I'm doing unit tests (using Karma &amp; PhantomJS)</p>
  
  <p>It is instanciated as follows:</p>
  
  <h2>bootstrap.js</h2>
  
  <pre><code>require('./app.js');
  
  var app = document.URL.indexOf( 'http://' ) === -1 &amp;&amp; document.URL.indexOf( 'https://' ) === -1;
  
  if ( app ) {
      console.log('App running on a mobile device');
      document.addEventListener("deviceready", function(){
          angular.bootstrap(document, ['esme']);
      });
  } else {
      console.log("App running in a browser");
      angular.element(document).ready(function() {
          angular.bootstrap(document, ['esme']);
      });
  }
  </code></pre>
  
  <h2>app.js</h2>
  
  <pre><code>var esme = angular.module('esme', ['ui.router', 'ngAnimate', 'ngTouch', 'DataStore', 'angular-carousel', 'SessionParams', 'hmTouchEvents']);
  
  esme.run(['$location', '$rootScope', '$state', 'NotificationManager', function($location, $rootScope, $state, NotificationManager) {
      console.log('run');
  
      NotificationManager.init();
  
      $rootScope.$on('$locationChangeSuccess', function (event, current, previous) {
          if($state.current.data)
              $rootScope.title = $state.current.data.title;
      });
  }]);
  </code></pre>
  
  <h2>Test.js</h2>
  
  <pre><code>describe('TestController', function() {
      var $controller;
      var $rootScope;
  
      beforeEach(module('esme'));
  
      beforeEach(module(function($urlRouterProvider) {
          $urlRouterProvider.deferIntercept();
      }));
  
      beforeEach(inject(function(_$controller_, _$rootScope_){
          // The injector unwraps the underscores (_) from around the parameter names when matching
          $controller = _$controller_;
          $rootScope = _$rootScope_.$new();
      }));
  
      describe('$scope.cheer', function() {
          var $scope, controller;
  
          beforeEach(function() {
              $scope = $rootScope;
              controller = $controller('Main', { $scope: $scope });
          });
  
          describe("#hello()", function(){
              it('ensures hello is correct', function() {
                  $scope.test.should.equal('test');
              });
          });
      });
  });
  </code></pre>
  
  <p>The output of a browser console is the following:</p>
  
  <blockquote>
    <p>"App running in a browser"</p>
    
    <p>"config"</p>
    
    <p>"run"</p>
  </blockquote>
  
  <p>But the output of the unit test is the following:</p>
  
  <blockquote>
    <p>INFO [karma]: Karma v0.12.31 server started at <a href="http://localhost:9876/" rel="nofollow">http://localhost:9876/</a></p>
    
    <p>[ .. Karma / PhantomJS stuff .. ]</p>
    
    <p>LOG: 'App running in a browser'</p>
    
    <p>WARN [web-server]: 404: /views/Main/Login.html</p>
    
    <p>LOG: 'config'</p>
    
    <p>LOG:'run'</p>
    
    <p>LOG: 'config'</p>
    
    <p>LOG: 'run'</p>
    
    <p>PhantomJS 1.9.8 (Windows 7): Executed 1 of 1 SUCCESS (0.007 secs / 0.001 secs)</p>
    
    <p>WARN [web-server]: 404: /views/Main/Login.html</p>
    
    <p>[17:16:14] Finished 'test:unit' after 5.31 s</p>
  </blockquote>
  
  <p>I'm still learning how to mock an angular application so I strongly believe that I made some obvious mistakes in the test file. Can you please help me find them and explain why did this behavior happened ?</p>
  
  <p>The only clue I may have for now comes from <a href="https://github.com/angular/angular.js/blob/ce669edfa14dc7eb7c389d2f82c9c98399a9009b/docs/content/guide/module.ngdoc" rel="nofollow">Angular's doc</a>, <em>should I declare a module only for running the app ?</em>:</p>
  
  <blockquote>
    <p>Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be
    injected into run blocks. This is to prevent further system
    configuration during application run time.</p>
    
    <p>Run blocks are the closest thing in Angular to the main method. A run block is the code which needs to run to kickstart the application.
    It is executed after all of the service have been configured and the
    injector has been created. Run blocks typically contain code which is
    hard to unit-test, and for this reason should be declared in isolated
    modules, so that they can be ignored in the unit-tests.</p>
  </blockquote>
  
  <p>Thanks for your help!</p>