gpt4 book ai didi

angularjs - 运行 Protractor 示例时获取 "ReferenceError: angular is not defined"

转载 作者:行者123 更新时间:2023-12-03 07:56:25 25 4
gpt4 key购买 nike

我正在尝试运行 Protractor 示例来测试 PasswordController,但我得到了这个“ReferenceError:angular is not defined”。可能是什么原因呢?以下是测试文件:

// conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
files: [
'../node_modules/angular-mocks/angular-mocks.js',
'../node_modules/angular/angular.js',
'app.js'
]
}

spec.js 是:

// spec.js
describe('PasswordController', function() {
beforeEach(module('app'));

var $controller;

beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));

describe('$scope.grade', function() {
it('sets the strength to "strong" if the password length is >8 chars', function() {
var $scope = {};
var controller = $controller('PasswordController', { $scope: $scope });
$scope.password = 'longerthaneightchars';
$scope.grade();
expect($scope.strength).toEqual('strong');
});
});
});

最后:

angular.module('app', [])
.controller('PasswordController', function PasswordController($scope) {
$scope.password = '';
$scope.grade = function() {
var size = $scope.password.length;
if (size > 8) {
$scope.strength = 'strong';
} else if (size > 3) {
$scope.strength = 'medium';
} else {
$scope.strength = 'weak';
}
};
});

最佳答案

你需要在angular-mocks之前包含angular

关于angularjs - 运行 Protractor 示例时获取 "ReferenceError: angular is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31239540/

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