gpt4 book ai didi

javascript - 禁用不被视为 HTML 属性

转载 作者:行者123 更新时间:2023-11-28 21:21:15 24 4
gpt4 key购买 nike

我在html中有这个按钮

 const dom = new JSDOM(`
<button id="ref_button" type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">`)

我正在使用 Chai 进行这样的测试:

 dom.window.document.getElementById("ref_button").should.have.attr('type');

而且效果很好。 但是,如果我想以相同的方式测试 disabled 属性,则测试不起作用:

  dom.window.document.getElementById("ref_button").should.have.attr('[disabled]');

Itt 总是说属性存在。这是不正常的,因为根据条件它不应该存在(当我用有效数据填写表格时)。

我在 Chai 中做错了什么吗?

最佳答案

我对 Chai 了解不多,只是通过它尝试下面的一个

prop() or property()

dom.window.document.getElementById("ref_button").should.have.prop('disabled');

dom.window.document.getElementById("ref_button").should.have.property('disabled');

更新的代码段

你能不能像下面这样试试

is()

dom.window.document.getElementById("ref_button").is('[disabled]')).toBe(true)

以上可能有效,请尝试。如果没有,也试试下面的一个

hasAttr() or hasAttribute()

dom.window.document.getElementById("ref_button").hasAttribute('disabled')

关于javascript - 禁用不被视为 HTML 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51042563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com