Running Tests That Rely on JavaScript
OK, let’s take this up a notch. Setting up testing with JavaScript support is not going to be so straightforward with Docker. But I think you’re ready to handle it.
Imagine, if you will, that we have an enhanced version of our /welcome page that has extra behavior that only works with JavaScript enabled. In fact, when functioning correctly, this JavaScript literally adds the message “ENHANCED!” on the page.
Here’s my rather crude implementation in app/views/welcome/index.html.erb:
| <% content_for :head do %> |
| <script type="text/javascript"> |
| document.addEventListener("DOMContentLoaded",function(){ |
| document.getElementsByTagName('h1')[0].append(' ENHANCED!'); |
| }); |
| </script> |
| <% ... |
Get Docker for Rails Developers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.