I'm using Jasmine to unit test my Angular App. How can I test form validation in my controller? For example, I have a login function:
$scope.login = function() {
if($scope.form_login.$valid) {
//send request with username and password
};
};
I'm trying to set $valid
to true
, but I can't access the form here. I got an error TypeError: Cannot set property '$valid' of undefined
:
it('should not send request if form validation fails', function() {
$controller('loginController', {$scope: $scope});
$scope.form_login.$valid = true;
$scope.login();
})