我试图用角度js进行单元测试,但这并不容易。
我想进行一个简单的琐碎测试:</ p>
describe('Edition Controllers', function(){
beforeEach(module('DOPCjsControllers.controller'));
it('should check a simple test', inject(function($controller) {
var scope = {};
var editionCtrl = $controller('EditionController', {$scope : scope} );
expect(scope.test).toBe("lol");
}));
});
我的控制人员开始了:
'use strict';
/* Controllers */
var DOPCjsControllers = angular.module('DOPCjsControllers', []);
/**
*EditionController : Controlleur de gestion de la partie edition du logiciel.
*/
DOPCjsControllers.controller('EditionController', ['$scope', '$http', '$routeParams', '$filter', '$modal','$fileUploader', 'AUTH_EVENTS','NotificationFactory', 'NOTIF_STATUTS','Session','AuthService','$location',
function($scope, $http, $routeParams, $filter, $modal, $fileUploader, AUTH_EVENTS, NotificationFactory, NOTIF_STATUTS, Session, AuthService, $location){
$scope.test = "lol";
$scope.$on(AUTH_EVENTS.notAuthenticated, function(event){
//alert("Connectez vous d'abord");
console.log("notAuthenticated");
}); etc ...
当我执行测试时,我看到: Firefox 29.0.0(Ubuntu):执行1 of 1(1 FAILED)ERROR(0.645秒/0.011秒) INFO [观察者]:更改了文件&#34; /home/lionnel/angular-seed/test/unit/controllersSpec.js"。 Firefox 29.0.0(Ubuntu)版本控制器应该检查一个简单的测试FAILED minErr /&LT; @ /家/ lionnel /角种子/ bower_components /角度/ angular.js:78 loadModules /&LT; @ /家/ lionnel /角种子/ bower_components /角度/ angular.js:3810 forEach@/home/lionnel/angular-seed/bower_components/angular/angular.js:323 loadModules@/home/lionnel/angular-seed/bower_components/angular/angular.js:3775 createInjector@/home/lionnel/angular-seed/bower_components/angular/angular.js:3715 workFn@/home/lionnel/angular-seed/bower_components/angular-mocks/angular-mocks.js:2142
你知道诀窍是什么吗?
感谢您的帮助
不幸的是,当我写道:
describe('Edition Controllers', function(){
beforeEach(module('DOPCjsControllers'));
it('should check a simple test', inject(function($controller) {
var scope = {};
var editionCtrl = $controller('EditionController', {$scope : scope} );
expect(scope.test).toBe("lol");
}));
});
我有此错误消息: 错误:[$ injector:unpr]未知提供者:$ routeParamsProvider&lt; - $ routeParams http://errors.angularjs.org/1.2.16/ $注射器/ unpr?P0 =%24routeParamsProvider%20%3 C-%20个%24routeParams
答案 0 :(得分:2)
您的测试尝试加载名为&#34; DOPCjsControllers.controller&#34;的模块。你没有这样的模块。您定义的模块称为&#34; DOPCjsControllers&#34;:
var DOPCjsControllers = angular.module('DOPCjsControllers', []);
That's the name of the module ----^