angularjs - 模块“分析”不可用!您要么拼错了模块名称,要么忘记加载它
问题描述
我在控制器中添加了一个新的依赖项,并且由于现有的测试用例文件开始显示此错误。
Error: [$injector:modulerr] Failed to instantiate module Analytics due to:
[$injector:nomod] Module 'Analytics' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
这是 spec.js 文件
describe("Module filter Navigator Controllers Test",function(){
var $controller, $rootScope, $httpBackend, filtersNavigatorCtrl, $scope, $q, $timeout, $compile;
beforeEach(function(){
module('Analytics', function($provide) {
$provide.service('Analytics', function($q) {
this.trackEventFull = jasmine.createSpy('trackEventFull').andCallFake(function() {
var defer = $q.defer();
var promise = defer.promise;
promise.success = function(fn) {
promise.then(function(response) {
fn(messages, response.status, response.headers);
});
};
return promise;
});
});
});
beforeEach(inject(function(_$controller_,_$rootScope_,_$httpBackend_,_$q_, _$timeout_,_$compile_,_$filter_){
$q = _$q_;
$controller = _$controller_;
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
$timeout = _$timeout_;
$compile = _$compile_;
$filter_ = _$filter_;
$scope = $rootScope.$new();
filtersSelectionCtrl = $controller('filtersNavigatorCtrl',{$scope:$scope});
}));
这是 FilterNavigatiorCtrl.js
filtersControllers.controller('filtersNavigatorCtrl', ['$filter', '$scope', '$rootScope', '$timeout', '$compile', 'filterService', 'regionsService', 'Analytics',
function ($filter, $scope, $rootScope, $timeout, $compile, filterService, regionsService, Analytics) {
// controller code here
}
这是同一应用程序中的另一个控制器 filtersControllers.js。
var filtersControllers = angular.module('filterControllers', ['filterServices', 'regionsServices', 'messagesModule']);
这个模块的 app.js 看起来像这样
angular.module('filtersApp', [
'filterControllers',
'viewQueryControllers',
'entitlementModule',
'messagesModule',
'ngSanitize',
'ngResource'
]);
我想模拟Analytics
FilterNavigatiorCtrl.js 文件使用的模块,但是当我这样做时,我得到了上述错误。如何解决这个问题?
解决方案
推荐阅读
- xamarin.forms - Guage 控件落后于其他控件
- javascript - 添加数组的连续元素
- flutter - 来自自己的流的每个项目的颤振块产量
- javascript - 无法使用 discord.js 获取带有 giphy 的 gif,制作机器人
- azure - Stop-AzureRmWebApp - 查找 Dll
- python - 在 Python 中使用 Pandas 清理我的数据
- python-3.x - 刚切换到 TensorFlow 2.1 并收到一些烦人的警告
- swift - 检索自定义类时 NSKeyedUnarchiver 返回 nil
- python - 输入包含对于 dtype“float64”来说太大的无穷大值
- command-line - 附加到 PATH 变量和创建一个新变量之间有什么区别?