[英]Disabled is not considered an HTML attribute
I have this button in html 我在html中有此按钮
const dom = new JSDOM(` <button id="ref_button" type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">`)
I am testing it like this using Chai: 我正在使用Chai进行如下测试:
dom.window.document.getElementById("ref_button").should.have.attr('type');
And it works perfectly. 而且效果很好。 But if I want to test the same way the disabled attribute the test doesn't work:
但是,如果我想以禁用属性的相同方式进行测试,则该测试将无法正常工作:
dom.window.document.getElementById("ref_button").should.have.attr('[disabled]');
Itt always says that the attribute exists. 它总是说该属性存在。 This is not normal, cause it should not exist according to teh condition (when I fill the form with valid data).
这是不正常的,因为根据条件(当我用有效数据填写表格时)它不应该存在。
Am I doing something wrong in Chai? 我在柴做错什么吗?
I don't know more about Chai, but just gone through it try below one 我对柴一无所知,只是尝试了一下
prop() or property()
dom.window.document.getElementById("ref_button").should.have.prop('disabled');
or 要么
dom.window.document.getElementById("ref_button").should.have.property('disabled');
Updated snippet 更新的代码段
Can you try like below 你能像下面这样尝试吗
is()
dom.window.document.getElementById("ref_button").is('[disabled]')).toBe(true)
Above one may work, please try it. 以上一种可能有效,请尝试一下。 If not, try below one also
如果不是,请尝试以下一项
hasAttr() or hasAttribute()
dom.window.document.getElementById("ref_button").hasAttribute('disabled')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.