我们的 AJAX 规范和within/有一些问题find。
我想做以下事情:
it 'allows to load more search results if there are any', focus: true, js: true do
fill_in 'search_term', with: '*'
click_button 'Search projects' # Sends a POST request
within 'table.projects' do
page.should have_content '1 of 2'
click_link 'Load more' # Sends an AJAX request
end
within 'table.projects' do
page.should have_content '2 of 2'
page.should have_link('Load more', visible: false)
end
end
可悲的是,这不起作用,因为第二个within似乎没有等待 AJAX 调用完成,而第一个似乎等待“正常” POST 请求(非 AJAX)。
使用 afind而不是 2ndwithin似乎可以解决问题:
it 'allows to load more search results if there are any', focus: true, js: true do
fill_in 'search_term', with: '*'
click_button 'Search projects' # Sends a POST request
within 'table.projects' do
page.should have_content '1 of 2'
click_link 'Load more' # Sends an AJAX request
end
find 'table.projects' do # find instead of within here!
page.should have_content '2 of 2'
page.should have_link('Load more', visible: false)
end
end
within在测试涉及 AJAX 请求的东西时使用它通常是一个坏主意吗?为什么我应该使用within而不是findthen ,因为它find似乎与AND等待 AJAX 一样?within!
非常感谢您的意见。