我正在尝试从我的项目中测试一个控制器,而我发现模块未找到错误。我看过类似的问题/答案,但解决方案对我没用。
我的角色代码如下:
angular.module('atMain')
.controller('MainController', ['$scope', 'atDirApi', 'atServer', '$sce', '$filter','$routeParams', '$location', '$window',
function($scope, atDirApi, atServer, $sce,
$filter, $routeParams, $location, $window) {
/* controller functions attached to $scope here*/
}]);
我的业力测试看起来像:
describe('', function() {
var MainCtrl;
beforeEach(module("atMain"));
beforeEach(inject(function($controller) {
MainCtrl = $controller("MainController");
}));
it('should showImage to !showImage', function() {
var $scope = {};
var controller = $controller('MainController', { $scope: $scope });
$scope.showImage = false;
$scope.showFunc();
expect($scope.showImage).toBe(true);
});
});
我的karma.conf文件包含以下内容:
files: [
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-mocks/angular-mocks.js',
'app.js',
'services/server-service/server-service.js',
'components/main/main-controller.js',
'components/main/main.js',
'tests/*.js'
],
我得到的错误是:
Uncaught Error: [$injector:nomod] Module 'atMain' 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.
答案 0 :(得分:2)
angular.module('atMain')
检索现有的Angular模块。以这种方式使用时,模块必须已经注册
angular.module('atMain', [...])
这是$injector:nomod
错误消息所说的内容。