查看 rspec 中 html 属性的测试
使用RSPEC视图,我想测试HTML元素具有所需的属性集:
我有以下视图:
app/views/reset/new.html.erb
<%= text_field_tag :email, params[:email], required: true %>
和测试:
spec/views/reset/reset/reset_spec。 RB
RSpec.describe "authentications/reset/new" do
require "rails_helper"
RSpec.describe "authentications/reset/new" do
it "email is required" do
render
expect(rendered).to have_selector("#email")
expect(rendered).to have_xpath("//input[@required='required']")
end
end
我想在测试中将两个期望结合起来,以便我可以检查元素电子邮件是否具有所需的属性。
Using rspec views, I want to test that an html element has the attribute required set:
I have the following view:
app/views/reset/new.html.erb
<%= text_field_tag :email, params[:email], required: true %>
and the test:
spec/views/reset/reset_spec.rb
RSpec.describe "authentications/reset/new" do
require "rails_helper"
RSpec.describe "authentications/reset/new" do
it "email is required" do
render
expect(rendered).to have_selector("#email")
expect(rendered).to have_xpath("//input[@required='required']")
end
end
I want to combine the two expects in the test so that I can check that the element email has the required attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参见 mdn> mdn:attribute selectors 。
See MDN: Attribute selectors.