我有一个angularjs web应用程序,并希望使用qunit进行单元测试。我有一个控制器:Angularjs和qunit测试
function RootCtrl($scope, $rootScope, $window, $location) {
// logger is empty at the start
$scope.logger = '';
// we have no login error at the start
$scope.login_error = '';
//
// Get values array of object
//
$rootScope.values = function (obj) {
var vals = [];
for(var key in obj) {
if(key !== '$$hashKey' && key !== 'checked')
vals.push(obj[key]);
}
return vals;
}
}
现在我想编写单元测试与qunit
values
功能。我将所有js
文件包括到test/index.html
和qunit.css
。现在我test.js
有以下内容:
var injector = angular.injector(['ng', 'myApp']);
var init = {
setup : function() {
this.$scope = injector.get('$rootScope').$new();
}
}
module('RootCtrl', init);
test('RootCtrl', function(){
var $controller = injector.get('$controller');
$controller('RootCtrl', {
$scope : this.$scope,
$location : this.$location
});
equal(['value'], $controller.values({'key' : 'value'}))
});
但我发现了错误:http://docs.angularjs.org/error/ $喷油器/ unpr P0 = $ rootElementProvider%20%3 C-%$ 20 rootElement的%20%3 C-%$ 20的位置% 20%3C-%$ 20路线在:
$controller('RootCtrl', {
$scope : this.$scope,
$location : this.$location
});
如何正确地注入控制器和使用$scope
,$rootScope
,$location
和它的另一个服务?
谢谢。
新增,得到相同的错误 – 0xAX