我怎么能在水豚测试一个网页有*不*重载(的JavaScript的onClick拦截曾)? [英] How can I test in Capybara that a page has *not* reloaded (JavaScript onClick intercept has worked)?
问题描述
我使用的水豚,黄瓜和骚灵。我测试附加到一个形式的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
这篇关于我怎么能在水豚测试一个网页有*不*重载(的JavaScript的onClick拦截曾)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!