2
AngularJS中的单元测试存在一些问题。我从Github角种子应用程序中拿走并编写了一些模块。现在,当我尝试测试它时,我有错误。 问题仅在单元测试中 - 浏览器应用程序工作正常。AngularJS中的单元测试错误 - 具有许多依赖性的控制器
我觉得应该很容易解决,但是我找不到我犯错的地方。
我的控制器:
'use strict';
angular.module('myApp.student', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/student', {
templateUrl: 'student.html',
controller: 'StudentCtrl'
});
}])
.controller('StudentCtrl', ['$scope', '$http', '$modal', '$log', function($scope, $http, $modal, $log) { ... }]);
我的单元测试dokumenty_test.js:
describe('myApp.student', function() {
beforeEach(module('myApp.student'));
describe('StudentCtrl controller', function(){
it('should ....', inject(function($controller) {
//spec body
var view1Ctrl = $controller(StudentCtrl');
expect(view1Ctrl).toBeDefined();
}));
});
});
而且从控制台错误: 错误:[$注射器:unpr]未知提供商:$ scopeProvider < - $ scope http://errors.angularjs.org/1.2.28/ $ injector/unpr?p0 =%24scopeProvider%20%3C-%20%24scope
在此先感谢
我添加了依赖ui.bootstrap和在karma.conf.js链接到ui.bootstrap:'https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js'和它的工作:)谢谢! – Alburnus 2015-02-08 10:13:36
不客气:) – tasseKATT 2015-02-08 10:16:21