1
使用RSpec,Capybara和Selenium测试Ruby on Rails应用程序。水豚不在乎event.preventDefault
我想单击一个具有href
的锚点,但由于event.preventDefault
而不应该导致任何地方。尽管如此,链接会将测试引导至链接页面,而不是保留在当前页面上。
我的第一印象是Javascript不起作用。除了其他测试,我可以看到Firefox做了一些事情,但我可以为这个特定测试说同样的事情。有什么我失踪?
如果我测试虚拟应用event.preventDefault
的页面按预期工作。
电流测试:
describe "In field group editor, user", type: :feature do
let(:user) { User.first }
before(:context) do
@structure = create(:structure)
end
it "should be able to create a checkbox" do
sign_in user
# should be login page
save_and_open_page # and it is
path_to_structure = edit_structure_path(structure_id: @structure.slug)
visit path_to_structure
find "#add-new-setting"
# should be structure page
save_and_open_page # and it is
click_on "add-new-setting" # this should fire an ajax call and preventDefault link behaviour
# should be still structure page
save_and_open_page # instead capybara it's gone to the new setting page
# ...
end
end