1

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

bezzoon
  • 1,755
  • 4
  • 24
  • 52
  • What kind of event do you want to test? Is it one of the default ones? (click, submit, change, keyup, etc.)? Or is it a custom one? And what does your test currently look like? – sbacarob Jan 18 '23 at 01:43

1 Answers1

0

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

codeanpeace
  • 194
  • 1
  • 5