Turbo Frames are a great way to build interactive pages without writing custom JavaScript. But how do you test them properly?
You can reach for system tests with Capybara and a real browser, but for many Turbo Frame interactions, this can be unnecessary overkill.
Rails integration tests are faster and more stable, and the turbo-rails gem provides dedicated Minitest assertions for working with Turbo Frames that many Rails developers don't know about.
How a Turbo Frame Request Works
When the browser loads content into a <turbo-frame> element, it adds an HTTP header to the request:
Turbo-Frame: "frame_name"
Enter fullscreen mode
Exit fullscreen mode
turbo-rails detects this header and renders the response using a minimal layout optimized for Turbo Frame requests instead of the full application layout.
This is a rendering optimization, since Turbo extracts the matching <turbo-frame> element from the response in the browser and swaps it into the page.…