Fillype Farias
Fillype Farias

Reputation: 660

capybara and click_on method + simple_form [javascript error]

I'm using minitest, capybara and poltergeist and this is the simple_form to test:

<%= simple_form_for :search,  url: ads_path , wrapper: :inline_form, html: {class: 'form-inline'}, :method => :get do |f| %>
  <%= f.error_notification %>
  <%= f.input :type_id, collection: @types, label_html: {class: 'form_home'}, selected: 'house'%>
  <%= f.input :city, label: 'Where?', placeholder: 'What is the city ?'%>
  <br>
  <br>
  <%= f.submit "Search", :class => "btn btn-primary btn-xl page-scroll" %>
<% end %>

The problem relies when I add the click_on 'Search'

 test "search correctly" do
    visit "/"
    select "house", :from => "search_type_id"
    fill_in 'search_city' , with: ""
    click_on 'Search'
  end

The javascrip error on the terminal:

Capybara::Poltergeist::JavascriptError:
Capybara::Poltergeist::JavascriptError: One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

    Error: Bounds are not valid.
    Error: Bounds are not valid.
        at http://127.0.0.1:43411/assets/application-1442915127e4fa1072f69aa9aa4d07ce85cdc5115df9b3a40da528ee05ebfe94.js:43537
        at http://127.0.0.1:43411/ads?utf8=%E2%9C%93&search%5Btype_id%5D=1&search%5Bcity%5D=&commit=Search:135
        test/integration/home_test.rb:16:in `block in <class:HomeTest>'

Is there other alternative ?

Upvotes: 0

Views: 214

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49870

You have two options, fix your JS or disable JS error reporting as mentioned in the error message.

To fix your JS either start by looking at the combined JS line 43537 to see why it's logging "Bounds are not valid" or do the same behavior in dev mode to figure out which individual JS file is producing the error and start debugging from there.

If on the other hand you don't care about fixing the cause of the error (you should care about it though) then you can configure your driver to not report JS errors with

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, js_errors: false)
end

as mentioned in the Poltergeist readme - https://github.com/teampoltergeist/poltergeist#customization

Upvotes: 0

Related Questions