In LiveView how do I call a handle_event from within a test.
@impl true
def handle_event("do_thing", _, socket) do
send(self(), :do_the_thing)
{:noreply, assign(socket, :cycler, true)}
end
In LiveView how do I call a handle_event from within a test.
@impl true
def handle_event("do_thing", _, socket) do
send(self(), :do_the_thing)
{:noreply, assign(socket, :cycler, true)}
end
You wouldn't directly call it, but take a look at the render_hook/3
function available with Phoenix.LiveViewTest
.
{:ok, view, _html} = live(conn, "/thermo")
assert view
|> element("#thermo-component")
|> render_hook(:refresh, %{deg: 32}) =~ "The temp is: 32℉"
source: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html#render_hook/3