gpt4 book ai didi

javascript - 参数 'controllerLogin' 不是函数,未定义 - AngularJs, karma 测试

转载 作者:行者123 更新时间:2023-11-29 10:42:33 25 4
gpt4 key购买 nike

各位 Genius 开发者,您好

目前我正在学习 AngularJs 并进行一些基本测试,但不断出现错误。请帮我解决这个问题。我四处寻找答案,但找不到任何东西。非常感谢您的任何帮助。

下面是错误。

 `Error: [ng:areq] Argument 'controllerLogin' is not a function, got undefined

我正在使用 WebStrom IDE。

这是我的 controllerLogin.js

'使用严格';

var loginApp = angular.module('loginApp',[]);

(function() {

//define this for the minification of javascripts
var loginScope=['$scope'];
var loginController = function($scope){
$scope.hello = "Hello Galaxy";

};

loginController.$inject = loginScope;
angular.module('loginApp').controller('loginController',loginController);

}());

下面是我的 loginSpec.js

'use strict';

describe("app module", function () {

beforeEach(module("loginApp"));

describe("controllerLogin", function () {
var scope,
controller;

beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller;
}));

it("should assign message to hello world", function () {
controller("controllerLogin", {$scope: scope});
expect(scope.message).toBe("Hello Galaxy");
});
});
});

下面是我的galaxytest.conf.js

 // list of files / patterns to load in the browser
files: [
'public/scripts/angular.js',
'public/scripts/angular-mocks.js',
'public/src/app/*.js',
'public/app.js',
'**/*.js',
'test/**/*Spec.js'
],

下面是我的 app.js

//Define all the module with no dependencies.
angular.module('loginApp',[]);


//Now Define Main Module of the Application
var galaxyFrontendApp = angular.module('galaxyFrontendApp',['ngRoute','ui.bootstrap','loginApp']);



galaxyFrontendApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login', {templateUrl: 'src/app/modules/login/views/viewLogin.html', action: 'loginApp.loginController'});
$routeProvider.otherwise({redirectTo: '/login'});
}]);

下面是我的 index.js

<body>
<div ng-view></div>



<!-- Please refer all the javascript files here -->
<!-- All the JS files from scripts folder -->
<script src="scripts/angular.js"></script>
<script src="scripts/angular-route.js"></script>
<script src="scripts/ui-bootstrap.js"></script>
<script src="app.js"></script>

<!-- All the JS files from App folder -->
<!-- Module Name - login -->
<script src="src/app/modules/login/controllerLogin.js"></script>
<script src="src/app/modules/login/directiveLogin.js"></script>




</body>

请指导我完成此操作。感谢您的时间和精力。

最佳答案

最后我得到了@DanWahlin 的帮助,他发现了问题所在。它与我的 galaxytest.conf.js 文件有关。

   files: [
"public/scripts/angular.js",
"public/scripts/angular-mocks.js",
"public/scripts/ui-bootstrap.js",
"public/scripts/angular-route.js",
"public/app.js",
"public/src/app/modules/login/controllerLogin.js",
"public/test/*Spec.js"
],

感谢开发者

关于javascript - 参数 'controllerLogin' 不是函数,未定义 - AngularJs, karma 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25903774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com