如何为ng-show编写单元测试用例?
<div class="fulldiv">
<div class="title-left">Establishment ID: <span>*</span></div>
<div class="input-right">
<input type="text" name="establishmentid" value="" ng-model="establishmentid" ng-maxlength="20" required>
<span ng-show="updatesiteform.establishmentid.$error.pattern">
Invalid establishmentid.
</span>
</div>
这是我验证字段
的单元测试用例我想确保显示正确的验证消息。如何做到这一点?
it('with a length of 1', function () {
//expect(form).toBeUndefined();
form.establishmentid.$setViewValue('1');
$scope.$digest();
expect(form.establishmentid.$valid).toBe(true);
});
答案 0 :(得分:1)
您应该在用于显示消息的相同值上检查true或truthy值。
it('with a length of 1', function () {
form.establishmentid.$setViewValue('1');
$scope.$digest();
expect(updatesiteform.establishmentid.$error.pattern).toBe(true);
});
您还可以使用Protractor在端到端测试中检查正确的错误消息。