单元测试模块无法加载+ karma + ionic angularAngular

时间:2018-03-05 09:48:16

标签: angularjs unit-testing ionic-framework karma-runner

尝试在单元测试中加载控制器模块karma + jasmine + ionic Angular 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/ $注射器/ 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"
}

1 个答案:

答案 0 :(得分:0)

请检查您是否已添加karma.conf.js中的所有文件,并以此链接为例:

在离子的情况下,您已在karma.conf文件中添加了主要离子文件

https://scotch.io/tutorials/testing-angularjs-with-jasmine-and-karma-part-1