Getting "ReferenceError: angular not defined" when running the Protractor example

I am trying to run the Protractor example to validate a PasswordController and I get this: "ReferenceError: angular is not defined". What could be causing this? Here are the test files:

// 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'
  ]
}
      

Run code


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');
    });
  });
});
      

Run code


Finally:

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';
    }
  };
});
      

Run code


+3


source to share


1 answer


You need to include angular before angular-mocks



0


source







All Articles