单元测试模块无法加载+ karma +离子angularAngular [重复]

问题描述 投票:0回答:1

试图在单元测试中加载控制器模块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/ $ injector / nomod?p0 = node.modules / angular / angular.js的App.View.Controllers: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
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.