我无法在不调用睡眠的情况下进行 rspec 测试:
it 'should allow deleting of foo brand attributes', :js => true do
@foo.brand_attributes << BrandAttribute.new(key: :test, value: :test)
@foo.save!
@foo.brand_attributes.length.should eq 1
visit('/admin')
expect(page).to have_content 'Test Foo'
click_link 'Edit'
# Edit opens a modal edit form with a list of attribute fields
page.should have_selector('#edit-modal-div', visible: true)
page.should have_selector('.attribute_fields', visible: true)
page.should have_selector('.attribute_fields input[type=hidden]')
# 1st sleep:
sleep 0.3
within(:css, "#edit-modal-div") do
# should update hidden input with destroy value
click_link 'Delete'
end
# 2nd sleep
sleep 0.3
page.should have_selector('.attribute_fields', visible: false)
within(:css, "#edit-modal-div") do
click_button 'Save'
end
page.find('.alert').should have_content 'successfully updated'
@foo = Foo.find(@food.id)
@foo.brand_attributes.length.should eq 0
我的期望是“page.should have_selector(”调用应该等到单击编辑后jquery动画完成,但由于某种原因,删除按钮不会更新隐藏字段,除非我在调用单击删除之前插入睡眠. 页面上的某些内容似乎还没有准备好。
wait_until 已被弃用,那么确定“删除”按钮已准备好单击的最佳方法是什么?
我尝试将我的链接更改为:
<a class="destroy_link" href="#" onclick="x = 4; return false;">Delete</a>
当我单击“删除”时,它不会将 x 设置为 4。看起来 onclick 处理程序在 capybara 触发点击时没有初始化。我有什么需要等待的吗?