Ademar Tutor
Ademar Tutor

Reputation: 1

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.

Upvotes: 0

Views: 290

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49870

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.

Upvotes: 1

Related Questions