简体   繁体   中英

Capybara is sending HTML format on request instead of JS on RSpec tests (Rails)

The feature works perfectly on the browser, however on the tests when Capybara clicks the submit button the request is processed as an HTML:

Processing by SearchController#index as HTML

Instead of:

Processing by SearchController#index as JS

This is my form on the view:

<%= form_with url: search_index_path, local: false, id: 'search-organization', method: :get do |f| %>

I'm using Rspec, capybara and poltergeist.

There are two possible reasons for this

  1. You aren't actually using the poltergeist driver for the given test, but are instead using rack_test which doesn't process JS

  2. You are using some ES 5.1+ feature/methods in your JS and not completely transpiling it to ES 5. Poltergeist uses PhantomJS which currently (v 2.1.1) only supports up to ES 5. You can make sure you turn on the js_errors: true option in the Poltergeist driver (which will show errors about non-existent methods, etc), however if you use some newer features (let, const, etc) PhantomJS will sometimes not raise an error and instead just silently ignore all the JS in the given file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM