【发布时间】:2016-04-08 14:59:35
【问题描述】:
我有一个指令,我要测试设置为属性的表单验证。
restrict: 'A',
scope: true,
表单名称由元素attr给出
$scope.theFormName = elem.attr('name');
我需要了解的是 if 语句
if ($scope.theForm.$valid) {
在我的 beforeEach 中用于我的单元测试
html = angular.element("<div ha-form-validation name=\"name\" class=\"ng-invalid\"></div>");
$rootScope = $rootScope.$new();
element = $compile(html)($rootScope);
$rootScope.$digest(element);
scope = element.scope();
scope.name = {
name: "test",
};
我已尝试在我的测试中将表单设置为有效
var form = scope.theFormName.$setValidity("properties", true);
但是 theFormName 正在返回 undefined
scope.theFormName.$valid = undefined
有没有办法将其设置为有效?
【问题讨论】:
标签: javascript angularjs validation unit-testing