运行Protractor示例时获取“ReferenceError:angular not defined”

时间:2015-07-06 07:02:56

标签: angularjs protractor

我正在尝试运行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';
    }
  };
});

1 个答案:

答案 0 :(得分:0)

你需要在角度模拟之前加入角度