带Karma的AngularJS测试控制器
发布时间:2020-12-17 08:53:54 所属栏目:安全 来源:网络整理
导读:我的控制器是: angular.module('mean').controller('ItemsController',['$scope',function ($scope) { $scope.contentTemplate = '/views/items/index.html'; $scope.subMenu = [ {name: 'Create Item',location: '/items/create'} ];}]); 我的测试非常简单
我的控制器是:
angular.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项目.相反,我得到的错误是:
是不是注入了$rootScope?那为什么它未定义?
你想要以美元符号开头的方法:
scope = $rootScope.$new(); // ^ 那应该解决它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |