2017-10-06 44 views
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 

回答

0

我只是忘了原说明书添加js: true

顺便说一句我不会删除这个问题,因为别人可能会失去时间寻找解决类似的问题,并没有意识到解决方案就是这么简单!