title: AngularJS unit test error: scope is undefined
body: <p>I have a problem with AngularJS unit testing. The scope in the unit test is undefined. But first the source code:</p>
  
  <p>The main angular module:</p>
  
  <pre><code>var app = angular.module('App', [ 
      'AppCtrl',
      'AppServices',
      'AppDirectives',    
      'ngGrid',
      'ui.bootstrap',
      'angular-growl',
      'ngAnimate'
  ]);
  </code></pre>
  
  <p>The controller module:</p>
  
  <pre><code>var appCtrl = angular.module('AppCtrl', []);
  </code></pre>
  
  <p>And finally the controller to test as a simplified version:</p>
  
  <pre><code>appCtrl.controller('SignalListCtrl', ['$scope',  
      function($scope) { 
          $scope.name = "World";
  }]);
  </code></pre>
  
  <p>Now the test. Version 1:</p>
  
  <pre><code>    describe("App", function () {
          beforeEach(module("App"));
  
          describe("SignalListCtrl", function () {
              var scope, controller;
  
              beforeEach(inject(function ($rootScope, $controller) {
                  scope = $rootScope.$new();
                  controller = $controller("SignalListCtrl", {$scope: scope});
                  //controller = $controller;
                  scope.$digest();
              }));
  
              it("should print World", function () {
                  //controller("SignalListCtrl", {$scope: scope});
                  expect(scope.name).toBe("World");
              });
          });
      });
  </code></pre>
  
  <p>The error Message: <code>scope is undefined</code>.</p>
  
  <p>The Version 2:</p>
  
  <pre><code>    describe("App", function () {
          beforeEach(module("App"));
  
          describe("SignalListCtrl", function () {
              var scope, controller;
  
              beforeEach(inject(function ($rootScope, $controller) {
                  scope = $rootScope.$new();
                  //controller = $controller("SignalListCtrl", {$scope: scope});
                  controller = $controller;
                  scope.$digest();
              }));
  
              it("should print World", function () {
                  controller("SignalListCtrl", {$scope: scope});
                  expect(scope.name).toBe("World");
              });
          });
      });
  </code></pre>
  
  <p>The error Message: <code>controller is not a function</code>.</p>
  
  <p>I use karma, if it depends on this.</p>
  
  <p>This is the karma.conf from angular-seed. These are all libs that I used. I think I don't need every lib to test, so I commented this out. If everything is uncommented, the same error occurs.
  edit: Every lib I use is in the karma.conf now. I get the same error messages.</p>
  
  <pre><code>module.exports = function(config){
      config.set({
      basePath : '../',
  
      files : [        
          'app/lib/jquery/jquery.js',
          'app/lib/jquery/jquery-ui-dialog.js',
          'app/lib/jquery/jquery-dialog.js',    
          'app/lib/angular/angular.js',
          'app/lib/angular/angular-*.js',
          'app/lib/angular/growl/*.js',          
          'app/lib/bootstrap/*.js',
          'app/lib/highcharts/highcharts.js',   
          'app/lib/highcharts/export.js',  
          'app/lib/xml2json/*.js', 
          'app/js/*.js',
          'test/lib/angular/angular-mocks.js',
          'test/unit/*.js'
      ],
  
      exclude : [
      ],
  
      autoWatch : true,
  
      frameworks: ['jasmine'],
  
      browsers : ['Firefox'],
  
      plugins : [
              'karma-junit-reporter',
              'karma-chrome-launcher',
              'karma-firefox-launcher',
              'karma-jasmine'
              ],
  
      junitReporter : {
        outputFile: 'test_out/unit.xml',
        suite: 'unit'
      }
  
  })};
  </code></pre>
  
  <p>Why the scope is undefined? The scope gets the $rootScope.$new().
  I hope someone can help me.</p>
  
  <p>Thanks.</p>
  
  <p>P.S: I asked the same question on GoogleGroups -> <a href="https://groups.google.com/forum/#!topic/angular/4oAEVLbEZT4" rel="nofollow">https://groups.google.com/forum/#!topic/angular/4oAEVLbEZT4</a></p>
  
  <p>But obviously nobody there can help me.</p>