1

I have this test case:

it 'should create new request from ajax form', js: true do
  visit root_path
  click_on 'new-order-link'
  expect {
    click_on 'submit-request'
  }.to change(Request, :count)
end

But I'm getting message, that count didn't changed. I suppose, that problem with async. When I add sleep(3) after click_on call, everything ok and test passed. But it's sound bad, that I should add sleep call in every test case with ajax.

4

1 回答 1

0

尝试使用 wait_until {检查 ajax 完成后显示的某些元素}。这将等到 ajax 完成,您可以继续检查其他内容。

编辑:我在 capybara 2.0 中看到这种方法将被弃用。有关更多信息以及如何在 capybara 2.0 中进行测试,请点击此处https://groups.google.com/forum/#!topic/ruby-capybara/qQYWpQb9FzY

于 2013-07-24T21:47:00.260 回答