title: Angularjs & Karma controller unit test injector:modulerr
body: <p>In order to apply some unit test to my AngularJS controller, I'm unable to get it working correctly...</p>
  
  <p>This is my Angularjs app declaration :</p>
  
  <pre><code>    var ogcApp = angular.module('OGC', [
      'ngAnimate',
      'xeditable',
      'ngRoute',
      'ogc.services',
      'ogc.controllers',
      'restangular',
      'AngularStomp',
      'ui.bootstrap',
      'ogc.directives',
      'mgcrea.ngStrap',
      'angularFileUpload',
      'jlareau.pnotify',
      'ngTagsInput'
  ]);
  </code></pre>
  
  <p>Here is my controller prototype :</p>
  
  <pre><code>angular.module('ogc.controllers').controller('applicantController', function ($scope, $log, $location, $cacheFactory, ngstomp, identityService, Restangular) { ...Some code... }
  </code></pre>
  
  <p>Here is my karma.conf.js :</p>
  
  <pre><code>    module.exports = function(config) {
    config.set({
  
      // base path that will be used to resolve all patterns (eg. files, exclude)
      basePath: '',
  
  
      // frameworks to use
      // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
      frameworks: ['jasmine'],
  
  
      // list of files / patterns to load in the browser
      files: [
          'src/main/webapp/static/js/lib/angular/angular.min.js',
          'src/main/webapp/static/js/lib/angular-animate/angular-animate.min.js',
          'src/main/webapp/static/js/lib/angular-xeditable/dist/js/xeditable.min.js',
          'src/main/webapp/static/js/lib/angular-route/angular-route.min.js',
          'src/main/webapp/static/js/lib/restangular/dist/restangular.min.js',
          'src/main/webapp/static/js/lib/AngularStompDK/dist/angular-stomp.min.js',
          'src/main/webapp/static/js/lib/angular-bootstrap/ui-bootstrap-tpls.min.js',
          'src/main/webapp/static/js/lib/angular-strap/dist/angular-strap.min.js',
          'src/main/webapp/static/js/lib/ng-file-upload/angular-file-upload.min.js',
          'src/main/webapp/static/js/lib/jquery/dist/jquery.min.js',
          'src/main/webapp/static/js/lib/pnotify/pnotify.core.js',
          'src/main/webapp/static/js/lib/ng-tags-input/ng-tags-input.min.js',
          'src/main/webapp/static/js/lib/angular-mocks/angular-mocks.js',
          'src/main/webapp/static/js/*.js',
          'src/test/karma/**/*.spec.js'
      ],
  
  
      // list of files to exclude
      exclude: [
  
      ],
  
  
      // preprocess matching files before serving them to the browser
      // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
      preprocessors: {
  
      },
  
  
      // test results reporter to use
      // possible values: 'dots', 'progress'
      // available reporters: https://npmjs.org/browse/keyword/karma-reporter
      reporters: ['progress'],
  
  
      // web server port
      port: 9876,
  
  
      // enable / disable colors in the output (reporters and logs)
      colors: true,
  
  
      // level of logging
      // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
      logLevel: config.LOG_DEBUG,
  
  
      // enable / disable watching file and executing tests whenever any file changes
      autoWatch: true,
  
  
      // start these browsers
      // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
      browsers: ['PhantomJS'],
  
  
      // Continuous Integration mode
      // if true, Karma captures browsers, runs the tests and exits
      singleRun: false
    });
  };
  </code></pre>
  
  <p>And this is my simple test :</p>
  
  <pre><code>    describe('UNIT : applicantController', function() {
  
      beforeEach(module('OGC'));
  
      var ctrl, scope, aSearchForm;
      // inject the $controller and $rootScope services
      // in the beforeEach block
      beforeEach(inject(function($controller, $rootScope) {
          // Create a new scope that's a child of the $rootScope
          scope = $rootScope.$new();
          // Create the controller
          ctrl = $controller('ogc.controllers.applicantController', {
              $scope: scope
          });
      }));
  
      it('should instantiate the controller properly', function () {
          expect(ctrl).not.toBeUndefined();
      });
  })
  </code></pre>
  
  <p>And I got this error on karma server logs :</p>
  
  <pre><code>PhantomJS 1.9.7 UNIT : applicantController should instantiate the controller properly FAILED
         Error: [$injector:modulerr] Failed to instantiate module restangular due to:
      ReferenceError: Can't find variable: _
  </code></pre>
  
  <p>And a simple :</p>
  
  <pre><code> expect(true).toBe(true);
  </code></pre>
  
  <p>Doesn't work while the beforeEach with the injection is there, so I think the problems is on the dependencies injection but where ?..</p>