我已经写了一个指令来验证输入。如何为该指令编写单元测试?
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;
});
}
};
});