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?
You want the method which starts with dollar sign:
scope = $rootScope.$new();
// ^
That should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With