6

My Controller is:

angular.module('mean').controller('ItemsController', ['$scope', function ($scope) {
  $scope.contentTemplate = '/views/items/index.html';
  $scope.subMenu = [
    {name: 'Create Item', location: '/items/create'}
  ];
}]);

My test is pretty simple:

  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);
    });

  });

What I want is to test that there is one subMenu item. Instead, the error I get is:

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()')

Isn't $rootScope injected? So why is it undefined?

1 Answer 1

19

You want the method which starts with dollar sign:

scope = $rootScope.$new();
//                 ^

That should fix it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.