水豚不在乎event.preventDefault

Capybara doesn't care about event.preventDefault

使用 RSpec、Capybara 和 Selenium 在 Rails 应用程序上测试 Ruby。

我想单击一个带有 href 但由于 event.preventDefault 而不应指向任何地方的锚点。尽管如此,link 将测试引导至 linked 页面,而不是留在当前页面上。

我的第一印象是 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

我只是忘记在初始描述中添加 js: true

顺便说一句,我不会删除这个问题,因为其他人可能会浪费时间寻找解决类似问题的方法,却没有意识到解决方案是如此简单!