title: AngularJS Testing Controller with Karma
body: <p>My Controller is:</p>
  
  <pre><code>angular.module('mean').controller('ItemsController', ['$scope', function ($scope) {
    $scope.contentTemplate = '/views/items/index.html';
    $scope.subMenu = [
      {name: 'Create Item', location: '/items/create'}
    ];
  }]);
  </code></pre>
  
  <p>My test is pretty simple:</p>
  
  <pre><code>  describe('ItemsController', function () {
      var scope;
  
      beforeEach(module('mean'));
  
      beforeEach(inject(function($controller, $rootScope) {
        scope = $rootScope.new();
        $controller('ItemsController', {
          $scope: scope
        });
  
      }));
  
  
      it('should have sub menu items loaded properly', function () {
        expect(scope.subMenu.length).toBe(1);
      });
  
    });
  </code></pre>
  
  <p>What I want is to test that there is one subMenu item. Instead, the error I get is:</p>
  
  <blockquote>
    <p>PhantomJS 1.9.7 (Mac OS X) ItemsController should have sub menu items
    loaded properly FAILED TypeError: 'undefined' is not a function
    (evaluating '$rootScope.new()')</p>
  </blockquote>
  
  <p>Isn't $rootScope injected? So why is it undefined?</p>