Search⌘ K
AI Features

Connecting the JavaScript to the Server Code

Explore how to connect JavaScript to Rails server code effectively in testing. Learn to handle Ajax calls that fetch JSON data, update controller responses, and resolve test timing issues using Capybara's waiting capabilities. This lesson helps you understand key techniques for integrating frontend JavaScript with backend code to ensure robust and reliable system tests.

Connecting JavaScript to server code

Were we to run the RSpec tests now that we’ve moved all the logic to JavaScript, we’d find that both tests in spec/system/add_task_spec.rb fail. The first test, which did not run in the JavaScript browser, fails because, without JavaScript, the tasks don’t display. That’s to be expected, and the test can be removed as its logic is now covered elsewhere.

Failing test

The JavaScript test also fails for a couple of reasons. The ...