Phoenix.LiveViewTest.render_change
render_change
, go back to Phoenix.LiveViewTest module for more information.
Sends a form change 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-change
attribute in it. The event name
given set on phx-change
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.
If you need to pass any extra values or metadata, such as the "_target"
parameter, you can do so by giving a map under the value
argument.
It returns the contents of the whole LiveView or an {:error, redirect}
tuple.
Examples
{:ok, view, html} = live(conn, "/thermo")
assert view
|> element("form")
|> render_change(%{deg: 123}) =~ "123 exceeds limits"
# Passing metadata
{:ok, view, html} = live(conn, "/thermo")
assert view
|> element("form")
|> render_change(%{_target: ["deg"], deg: 123}) =~ "123 exceeds limits"
As with render_submit/2
, hidden input field values can be provided like so:
refute view
|> form("#term", user: %{name: "hello"})
|> render_change(%{user: %{"hidden_field" => "example"}}) =~ "can't be blank"
Sends a form change event to the view 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 temp is: 30℉"
assert render_change(view, :validate, %{deg: 123}) =~ "123 exceeds limits"