我正在尝试为我的项目设置单元测试环境,但遇到了一些问题。我正在尝试将 Testacular 与 Jasmine 一起使用来测试我的 AngularJS 代码。
我有一个模块Services
,它有一个名为 KeepAlive 的工厂方法。这是它的设置。
angular.module('services', []).factory('KeepAlive', ['$rootScope', function($rootScope){
//My Code
}]);
该模块附加到一个名为MainModule
. 这是它的代码。
angular.module('MainModule', ['filters', 'services', 'directives', 'ui'])
.config(['$httpProvider', function($httpProvider){
//My Code
}]).run(['$rootScope', '$timeout', '$routeParams', 'KeepAlive', function($rootScope, $timeout, $routeParams, KeepAlive){
//My Code
}]);
所以现在我想为我的测试添加这段代码。所以这是我的睾丸文件设置。
JASMINE,
JASMINE_ADAPTER,
'assets/lib/jquery/jquery-1.7.1.js',
'assets/lib/angular/angular.js',
'assets/lib/angular/angular-ui.js',
'jsTests/MockingLib/angular-mocks.js',
'assets/scripts/modules/Admin.js',
'assets/scripts/modules/MainModule.js',
'assets/scripts/services/KeepAlive.js',
'assets/scripts/services/Admin.js',
'assets/scripts/filters.js',
'assets/scripts/directives.js',
'assets/scripts/controllers/admin/*.js',
现在这在我的睾丸控制台中引发了错误。这是我得到的错误。
Error: Unknown provider: KeepAliveProvider <- KeepAlive
at Error (<anonymous>)
at d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2627:8
at Object.getService [as get] (d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2755:32)
at d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2632:38
at getService (d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2755:32)
at Object.invoke (d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2773:6)
at d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2637:71
at Array.forEach (native)
at forEach (d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:110:11)
at Object.createInjector [as injector] (d:/Work/Workspace/TalentNetwork/assets/lib/angular/angular.js:2637:3)
这是我的 Jasmine 测试用例。
beforeEach(function () {
admin = module("MainModule");
module("services");
});
我错过了什么?我是睾丸的新手。提前致谢。