title: Angularjs - how to unit test form validation
body: <p>I'm using <a href="http://jasmine.github.io/" rel="nofollow">Jasmine</a> to unit test my Angular App. How can I test form validation in my controller? For example, I have a login function:</p>
  
  <pre><code>$scope.login = function() {
      if($scope.form_login.$valid) {
        //send request with username and password
      };
  };
  </code></pre>
  
  <p>I'm trying to set <code>$valid</code> to <code>true</code>, but I can't access the form here. I got an error <code>TypeError: Cannot set property '$valid' of undefined</code>:</p>
  
  <pre><code>it('should not send request if form validation fails', function() {
      $controller('loginController', {$scope: $scope});
      $scope.form_login.$valid = true;
      $scope.login();
  })
  </code></pre>