title: Karma Jasmine Angular Error: [$injector:nomod]
body: <p>Short version: When I run karma, angular is telling me it cannot inject my 'common' module.
  The actual error is:</p>
  
  <pre><code>Error: [$injector:nomod] http://errors.angularjs.org/1.5.5/$injector/nomod?p0=common
  </code></pre>
  
  <p>Here's the details:</p>
  
  <p>My Karma <strong>test.js</strong></p>
  
  <pre><code>"use strict";
  
  describe('Testing ModuleToTest',function(){
      beforeEach(module('ModuleToTest'));
  
      var $scope = {};
      var factory = {...make up stuff...}
  
      // inject - access angular controller 
      beforeEach(inject([
          '$controller','$rootScope',
          function($ctrl,$rs){
          $scope = $rs.$new();
          $ctrl('ModuleToTestCtrl',{
              $scope:$scope,
              CommonFactory:factory
          });
      }]));
  
      it('should define a someStuff object',function(){
          expect(testScope.someStuff).toBeDefined();
      });
  });
  </code></pre>
  
  <p>My <strong>ModuleToTest</strong> definition:</p>
  
  <p>module.js file:</p>
  
  <pre><code>angular.module('ModuleToTest',[]);
  </code></pre>
  
  <p>controller.js file:</p>
  
  <pre><code>angular.module('ModuleToTest')
  .controller('ModuleToTestCtrl',
  ['$scope','$http','CommonFactory',
  function($scope,factory){
      $scope.someStuff = ['foo','bar'];
  }]);
  </code></pre>
  
  <p>The module that defines the <strong>CommonFactory</strong>:</p>
  
  <p>module.js file:</p>
  
  <pre><code>angular.module('common',[]);
  </code></pre>
  
  <p>CommonFactory.js</p>
  
  <pre><code>angular.module('common')
  .factory('CommonFactory',['$http',function($http){
     // do factory stuff here
  }]);
  </code></pre>
  
  <p>Application module defintion, app.js:</p>
  
  <pre><code>angular.module('MyMainApp',['ModuleToTest', ... , 'common']);
  </code></pre>
  
  <p>karma.config.js:</p>
  
  <pre><code>// frameworks to use
  // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
  frameworks: ['jasmine'],//'requirejs'],
  
  
  // list of files / patterns to load in the browser
  files: [
    {pattern: 'js/vendor/angular/*.js'},
    {pattern: 'js/common/*.js'},
    {pattern: 'moduleToTest/js/*.js'},
    {pattern: 'moduleToTest/*.html'},
    {pattern: 'js/*.js'},
    {pattern: 'index.html'},
    {pattern: 'test/test.js'}
  ],
  
  
  // list of files to exclude
  exclude: [
    'js/vendor/bootstrap*.js',
    'js/vendor/jquery*.js'
  ],
  </code></pre>
  
  <p>Quick caveate: MyMainApp works as I expect it to.  I am just beginning to use Karma to build unit tests for my applications modules.  Eventually I will build the unit tests for MyMainApp, but I'm trying to start small.  </p>
  
  <p>Any suggestions or clarifications are welcome, in addition to answers!  Thank you!</p>
  
  <p><strong>UPDATE</strong>: After helpful responses (thank you by the way!)  In short, I'm getting the same error, but I've tried to simplify the problem.</p>
  
  <p>I removed any mention of 'common' from my ModuleToTest.  And Karma is still complaining about 'common'.  Here's the details:</p>
  
  <p>My Karma test.js</p>
  
  <pre><code>"use strict";
  
  describe('Testing ModuleToTest',function(){
      var testScope = {};
  
      beforeEach(function(){
  
          module('ModuleToTest');
  
          inject(function($rootScope,$controller){
              testScope = $rootScope.$new();
              $controller('ModuleToTestCtrl',{
                  $scope: testScope
              }); 
          });
      });
  
      // No it statement for now because the module won't even load
  });
  </code></pre>
  
  <p>My <strong>ModuleToTest</strong> definition:</p>
  
  <p>module.js file (<em>notice no reference to CommonFactory</em>):</p>
  
  <pre><code>angular.module('ModuleToTest',[]);
  </code></pre>
  
  <p>controller.js file (<em>notice the removal of CommonFactory</em>):</p>
  
  <pre><code>angular.module('ModuleToTest')
  .controller('ModuleToTestCtrl',
  ['$scope',function($scope){
      $scope.someStuff = ['foo','bar'];
  }]);
  </code></pre>
  
  <p><strong>ANSWER</strong>: Given the simplified version, the solution was to put <em>angular-mocks.js</em> after <em>angular.min.js</em> in the <em>karma.conf.js</em> file.</p>
  
  <p>I hope this saves somebody else the trouble.  </p>