Last Updated: July 06, 2018
· timsegraves

The Capybara and the JavaScript Datepicker

tldr; Turn off JavaScript input components in test mode to not have to enable JS in Capybara integration tests.

Frustrated with the slowness and the pain in setting up JavaScript enabled Capybara tests in Rails/Rspec I decided the best solution to keep my tests fast and my sanity intact was to switch my JavaScript enabled inputs to standard inputs in test mode.

- if Rails.env.test?
  = f.input :start_date, label: 'Date:'
- else
  %label Date:{:data => {:"date-format" => "yyyy-mm-dd"}}

Above you can see the datepicker class on the input-append div tag gets converted to a datepicker via JavaScript. Capybara can't fill in a date for that field without enabling JavaScript so instead I'm just rendering a standard Simple Form input field in test mode.

Really hoping this gets my tests back on track so I can launch soon.