File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ nav_order: 6
1010
1111## main
1212
13- * Allow I18n calls in render?
14- * Split render lifecycle into separate methods, to be able to test component methods that rely on ` t(...) ` directly
13+ * Allow I18n calls in render?.
14+ * Split render lifecycle into separate methods, to be able to test component methods that rely on ` t(...) ` directly.
15+ * Added ` setup_render ` test helper to allow testing of component methods that rely on ` t(...) ` without rendering the component.
1516
1617 * 23tux*
1718
Original file line number Diff line number Diff line change @@ -301,6 +301,23 @@ render_inline(MyComponent.new)
301301assert_text(" Hello, World!" )
302302```
303303
304+ ### ` #setup_render(component) ` → [ ViewComponent::Base]
305+
306+ Triggers the render setup of a component without actually rendering it.
307+ The method is also called internally by ` #render_in ` when a component is rendered.
308+ Useful for testing methods of components that need access to the view context or the ` @virtual_path ` variable like I18n's ` t(...) ` helper.
309+
310+ ``` ruby
311+ class MyComponent < ViewComponent ::Base
312+ def message
313+ t(" hello.world" )
314+ end
315+ end
316+
317+ component = setup_render(MyComponent .new )
318+ assert_equal(component.message, " Hello, World!" )
319+ ```
320+
304321### ` #render_preview(name, from: __vc_test_helpers_preview_class, params: {}) ` → [ Nokogiri::HTML5]
305322
306323Render a preview inline. Internally sets ` page ` to be a ` Capybara::Node::Simple ` ,
You can’t perform that action at this time.
0 commit comments