Skip to content

Commit daba8a9

Browse files
committed
added docs
1 parent ee51aaf commit daba8a9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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

docs/api.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ render_inline(MyComponent.new)
301301
assert_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

306323
Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,

0 commit comments

Comments
 (0)