Phoenix.LiveViewTest.render_click
render_click
, go back to Phoenix.LiveViewTest module for more information.
Sends a click event given by element
and returns the rendered result.
The element
is created with element/3
and must point to a single
element on the page with a phx-click
attribute in it. The event name
given set on phx-click
is then sent to the appropriate LiveView
(or component if phx-target
is set accordingly). All phx-value-*
entries in the element are sent as values. Extra values can be given
with the value
argument.
If the element is does not have a phx-click
attribute but it is
a link (the <a>
tag), the link will be followed accordingly:
- if the link is a
live_patch
, the current view will be patched - if the link is a
live_redirect
, this function will return{:error, {:live_redirect, %{to: url}}}
, which can be followed withfollow_redirect/2
- if the link is a regular link, this function will return
{:error, {:redirect, %{to: url}}}
, which can be followed withfollow_redirect/2
It returns the contents of the whole LiveView or an {:error, redirect}
tuple.
Examples
{:ok, view, html} = live(conn, "/thermo")
assert view
|> element("buttons", "Increment")
|> render_click() =~ "The temperature is: 30℉"
Sends a click event
to the view
with value
and returns the rendered result.
It returns the contents of the whole LiveView or an {:error, redirect}
tuple.
Examples
{:ok, view, html} = live(conn, "/thermo")
assert html =~ "The temperature is: 30℉"
assert render_click(view, :inc) =~ "The temperature is: 31℉"