在LiveView中如何从测试中调用handle_event
@impl true
def handle_event("do_thing", _, socket) do
send(self(), :do_the_thing)
{:noreply, assign(socket, :cycler, true)}
end
您不会直接调用它,但可以查看Phoenix.LiveViewTest
可用的render_hook/3
函数。
{:ok, view, _html} = live(conn, "/thermo")
assert view
|> element("#thermo-component")
|> render_hook(:refresh, %{deg: 32}) =~ "The temp is: 32℉"
来源:https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html render_hook/3