2017-10-06 43 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

順便說一句我不會刪除這個問題,因爲別人可能會失去時間尋找解決類似的問題,並沒有意識到解決方案就是這麼簡單!