Connecting the JavaScript to the Server Code

Learn how to make the failing JavaScript test pass and how to connect the JavaScript to the server code.

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 simple one is that JavaScript makes a new Ajax call to get the JSON data for the tasks. To make that work, we need to make a small change to the ProjectsController#show method:

Get hands-on with 1200+ tech skills courses.