我的控制器是:
原文链接:https://www.f2er.com/angularjs/141019.htmlangular.module('mean').controller('ItemsController',['$scope',function ($scope) { $scope.contentTemplate = '/views/items/index.html'; $scope.subMenu = [ {name: 'Create Item',location: '/items/create'} ]; }]);
我的测试非常简单:
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); }); });
我想要的是测试有一个subMenu项目.相反,我得到的错误是:
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()’)
是不是注入了$rootScope?那为什么它未定义?