DOM中的hasAttribute无法正常工作 [英] hasAttribute in DOM not working properly
问题描述
我在tect.html文件中有此表单,我想测试按钮是否被禁用:
I have this form in an tect.html file and I want to test if the button is disabled or not:
<button id="ref_button"....[disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
当表单数据无效时,我正在使用量角器,黄瓜和Chaidom来测试此按钮是否被禁用,因此我按如下方式检查其属性已禁用:
I am using protractor, cucumber, and chai dom to test if this button is disabled when the form data are invalid, so I check its attribute disabled like this:
JSDOM.fromFile("file.html").then(dom => {
dom.window.document.getElementById("ref_button").has.attr('disabled').should.be.true;
});
});
现在测试失败了,因为它总是会发现属性处于禁用状态,无论按钮是否处于禁用状态,数据是否有效.
Now the test fails because it always finds the attribute disabled, when the button is disabled or not, when the datas are valid or not.
我在做什么错了?
推荐答案
对于angularJs,您应在html中使用指令 ng-disabled
For angularJs, you should use directive ng-disabled
in your html
来自官方文档:
因为我们不能使用插值,所以必须使用特殊指令在禁用属性内.有关更多信息,请参见插值指南信息.
A special directive is necessary because we cannot use interpolation inside the disabled attribute. See the interpolation guide for more info.
这篇关于DOM中的hasAttribute无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!