Skip to content

Commit

Permalink
render_async
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Aug 5, 2023
1 parent 706b657 commit fd1c4e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/phoenix_live_view/test/live_view_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ defmodule Phoenix.LiveViewTest do
@doc """
TODO
"""
def await_async(view_or_element, timeout \\ 100) do
def render_async(view_or_element, timeout \\ 100) do
pids =
case view_or_element do
%View{} = view -> call(view, {:async_pids, {proxy_topic(view), nil, nil}})
Expand All @@ -946,6 +946,8 @@ defmodule Phoenix.LiveViewTest do
{:ok, _} -> :ok
nil -> raise RuntimeError, "expected async processes to finish within #{timeout}ms"
end

render(view_or_element)
end

@doc """
Expand Down
12 changes: 4 additions & 8 deletions test/phoenix_live_view/integrations/assign_async_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ defmodule Phoenix.LiveView.AssignAsyncTest do
test "bad return", %{conn: conn} do
{:ok, lv, _html} = live(conn, "/async?test=bad_return")

await_async(lv)
assert render(lv) =~
assert render_async(lv) =~
"error: {:error, %ArgumentError{message: "expected assign_async to return {:ok, map} of\\nassigns for [:data] or {:error, reason}, got: 123\\n"}}"

assert render(lv)
Expand All @@ -25,24 +24,21 @@ defmodule Phoenix.LiveView.AssignAsyncTest do
test "missing known key", %{conn: conn} do
{:ok, lv, _html} = live(conn, "/async?test=bad_ok")

await_async(lv)
assert render(lv) =~
assert render_async(lv) =~
"expected assign_async to return map of\\nassigns for all keys in [:data]"

assert render(lv)
end

test "valid return", %{conn: conn} do
{:ok, lv, _html} = live(conn, "/async?test=ok")
await_async(lv)
assert render(lv) =~ "data: 123"
assert render_async(lv) =~ "data: 123"
end

test "raise during execution", %{conn: conn} do
{:ok, lv, _html} = live(conn, "/async?test=raise")

await_async(lv)
assert render(lv) =~ "error: {:error, %RuntimeError{message: "boom"}}"
assert render_async(lv) =~ "error: {:error, %RuntimeError{message: "boom"}}"
end
end
end

0 comments on commit fd1c4e7

Please sign in to comment.