2

I have written a directive to validate the input. How do I write a unit test for this directive?

angular.module('validationModule', [])
    .directive('validateName', function () {
        return {
            restrict: 'A',
            require: '?ngModel',
            link: function (scope, element, attrs, ngModel) {
                if (!ngModel) return;
                ngModel.$parsers.unshift(function (inputValue) {
                    var expr = inputValue.replace(/[^a-zA-Z0-9\s]/g, "");
                    ngModel.$viewValue = expr;
                    ngModel.$render();
                    return expr;
                });
            }
        };
    });
Re Captcha
  • 3,125
  • 2
  • 22
  • 34
Dosti
  • 161
  • 4
  • 17
  • This one helped me... http://stackoverflow.com/questions/15219717/to-test-a-custom-validation-angular-directive – Dosti Nov 12 '14 at 12:29

1 Answers1

0

This might be a good place to start.

Yaron Schwimmer
  • 5,327
  • 5
  • 36
  • 59