【发布时间】:2018-03-05 09:48:15
【问题描述】:
尝试在单元测试业力 + 茉莉花 + 离子角 1.5.3 中加载控制器模块。
模块/控制器文件
angular.module('App.View.Controllers', []).controller('ListController',
function($scope){
$scope._userName = UserService.getUserObject().maxperson;
});
describe("ListController", function(){
var $scope, $controller, ListController;
beforeEach(function () {
module('App.View.Controllers');
});
beforeEach(inject(function(_$rootScope_, _$controller_) {
$scope = $rootScope.$new();
$controller = _$controller_;
ListController = $controller('ListController', {$scope: $scope});
}));
it("has a dummy controller", function(){
expect(2+2).toEqual(4);
});
it('should be defined', function() {
expect(ListController).toBeDefined();
});
});
给我错误:
错误:[$injector:modulerr] 无法实例化模块 App.View.Controllers 由于: 错误:[$injector:nomod] 模块“App.View.Controllers”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=App.View.Controllers 在 node_modules/angular/angular.js:68:12
它是离子应用程序。实际上控制器也加载依赖项,但为了时间的缘故,我已经将它注释掉以制作一个简单的控制器加载。
package.json file
{
"name": "karma-2174",
"version": "1.0.0",
"description": "",
"devDependencies": {
"@uirouter/angularjs": "^1.0.3",
"angular": "^1.5.3",
"angular-mocks": "^1.5.3",
"jasmine-core": "^2.0.4",
"karma": "^1.5.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.1.0"
},
"scripts": {
"test": "karma start"
},
"author": "",
"license": "ISC"
}
【问题讨论】:
标签: angularjs unit-testing ionic-framework karma-runner