我使用的水豚,黄瓜和骚灵。我测试附加到一个形式的JavaScript函数提交按钮,其目的是捕捉提交事件和prevent它(在后台做一个AJAX请求)。带和不带AJAX,该网页将最终看起来一样,但AJAX方法更快,不会中断浏览体验等。
I am using Capybara, Cucumber and Poltergeist. I am testing a JavaScript function that is attached to a form submit button, which is intended to catch the submit event and prevent it (doing an AJAX request in the background). With and without AJAX, the page will end up looking the same, but the AJAX approach is much faster and does not interrupt the browsing experience etc.
我能做些什么,以测试的形式确实没有提交,而且变化是一个动态的AJAX调用,而不是重新加载的结果?
What can I do to test that the form was indeed not submitted, and that the changes are the result of a dynamic AJAX call rather than a reload?
的@jules的回答修改的版本:
Modified version of @jules' answer:
describe "My page", :js do
it "reloads when it should" do
visit "/"
expect_page_to_reload do
click_link "Reload me"
end
end
def expect_page_to_reload
page.evaluate_script "$(document.body).addClass('not-reloaded')"
yield
expect(page).not_to have_selector("body.not-reloaded")
end
end
上一篇:使用JQuery UI自动完成与ASP.NET的有效途径自动完成、有效途径、UI、JQuery
下一篇:AJAX InvalidStateError:试图使用对象不是,或不再,可用对象、不是、AJAX、InvalidStateError