Menu

Post image 1
Post image 2
1 / 2
0

Testing Turbo Frames in Rails Without a Browser

DEV Community: rails·Pavel Myslik·3 days ago
#2zmarL5M
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More