我的控制器文件:
define(['app', 'back123','loginService'], function (app) {
app.controller('loginController', function ($scope, $window, loginService, srvAuth) {$scope.emailValidate = function () {
var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (!pattern.test($scope.Email) ) {
$scope.email_invalid = true;
return false;
}
else {
$scope.email_invalid = false;
return true;
}
};
})});
我的测试文件:
define(['app', 'jquery', 'angular-mock', 'coreService', 'setterService', 'loginService','logincontroller'], function (App, $) {
describe('app', function () {
beforeEach(module('app'));
describe('logincontroller Email Vaidate', function () {
var scope;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
$controller("loginController", {
$scope: scope
});
}));
it('sets email false', function () {
scope.email_invalid = false;
scope.Email = 'true';
scope.emailValidate();
expect(scope.email_invalid).toEqual(false);
});
});
});});
在我的浏览器“源代码”选项卡中,加载了包含logincontroller函数的loginCtrl文件,该文件仍然存在错误
Error: [ng:areq] Argument 'loginController' is not a function, got undefined请建议
发布于 2015-11-27 12:16:35
由于我使用了angularAMD,所以我将代码更新为折叠:
angularAMD.inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
$controller("loginController", {
$scope: scope
});
});此外,我在定义模块中将angularAMD作为依赖项包括在内:
define(['app', 'jquery', 'angularAMD', 'angular-mock', 'coreService', 'setterService', 'loginService', 'loginController'], function (App, $, angularAMD) {https://stackoverflow.com/questions/33869870
复制相似问题