title: Unit-Testing AngularJS: Uncaught Error: [$injector:nomod] Module is not available! and ReferenceError: module is not defined when run Karma
body: <p>I've a small unitTest in Jasmine run with Karma. But when i run Karma it show errors:</p>
  <blockquote>
  <p>Uncaught Error: [$injector:nomod] Module 'material.controllers' is not
  available! You either misspelled the module name or forgot to load it.
  If registering a module ensure that you specify the dependencies as
  the second argument.</p>
  <p>FAILED Unit: LoginController encountered a
  declaration exception</p>
  <p>ReferenceError: module is not defined</p>
  </blockquote>
  <p>Here are my source code, config Karma file and unitTest.<br><br>
  <strong>karma.conf.js</strong></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: [
        '/home/tanpham/Angular/Dev/libs/angular/angular.js',
        '/home/tanpham/Angular/Dev/js/**/*.js',
        '/home/tanpham/Angular/Dev/js/*.js',
        '/home/tanpham/Angular/Test/*.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: {
      },
  </code></pre>
  <p><strong>index.html</strong></p>
  <pre><code>&lt;body ng-app=&quot;material&quot; ng-controller=&quot;AppController&quot;&gt;
      &lt;ui-view&gt;&lt;/ui-view&gt;
  &lt;/body&gt;
  </code></pre>
  <p><strong>app.js</strong></p>
  <pre><code>angular.module('material.controllers', []);
  angular.module('material.services', []);
  angular.module('material.directives',[]);
  angular.module('material.filters',[]);
  var app = angular.module('material', ['ui.router','material.directives','http-auth-interceptor','material.controllers','material.services','material.filters'])
  .config(function($stateProvider, $urlRouterProvider,$locationProvider) {
      $stateProvider
      .state('app', {
          url: &quot;/app&quot;,
          abstract: true,
          templateUrl: &quot;views/app.html&quot;
      }).state('login', {
          url: &quot;/login&quot;,
          templateUrl: &quot;views/login.html&quot;,
          controller: &quot;LoginController&quot;
      });
      
      $urlRouterProvider.otherwise('/login');
  })
  </code></pre>
  <p><strong>loginController</strong></p>
  <pre><code>angular.module('material.controllers').controller('LoginController', function($scope) {
      
        $scope.name = &quot;Ari&quot;;
        $scope.sayHello = function() {
           $scope.greeting = &quot;Hello &quot; + $scope.name;
        }
  });
  </code></pre>
  <p><strong>helloSpec.js</strong></p>
  <pre><code>describe('Unit: LoginController', function() {
      
        // Load the module with LoginController
        beforeEach(module('material.controllers'));
  
        var ctrl, scope;
        // 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('LoginController', {
            $scope: scope
          });
        }));
      
        it('should create $scope.greeting when calling sayHello', 
          function() {
            expect(scope.greeting).toBeUndefined();
            scope.sayHello();
            expect(scope.greeting).toEqual(&quot;Hello Ari&quot;);
        });
      
  })
  </code></pre>
  <p>So, i can do with that and my module's name is right?</p>