Ask A Question

Notifications

You’re not receiving notifications from this thread.

Test some simple javascript with Minitest and Capybara

Jesper asked in Testing

I'm seeking assistance on testing JavaScript that executes on the response page after a POST request.

So I have something like this

class YourControllerTest < ActionDispatch::IntegrationTest
  test 'submitting a POST request' do
    post '/your_controller/your_action', params: { your_param: 'some_value' }

    # Check if the response was a redirect (status code 202)
    assert_response :success

    # Now you can assert against the content of the redirected page
    assert_select 'h1', text: 'Expected Header'
  end
end

Which works, but the page object only contains an empty HTML page (<html><head></head><body></body></html>).

And I should be able to interact with the `page?, according to this https://github.com/teamcapybara/capybara#asynchronous-javascript-ajax-and-friends

I've experimented with both Selenium and the JavaScript driver for Capybara. In my test, there's plain JavaScript that alters the context of an HTML block, and I want to verify its functionality with a Minitest.

Can someone guide me on how to approach this effectively?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.