Extract LiveView async test helper
This commit is contained in:
@@ -14,7 +14,6 @@ defmodule MusicLibraryWeb.ConnCase do
|
||||
import Phoenix.LiveViewTest,
|
||||
# The default endpoint for testing
|
||||
only: [
|
||||
render_async: 1,
|
||||
render_change: 1,
|
||||
render_click: 3,
|
||||
render_hook: 2,
|
||||
|
||||
@@ -1,10 +1,42 @@
|
||||
defmodule MusicLibraryWeb.LiveTestHelpers do
|
||||
@moduledoc false
|
||||
@moduledoc """
|
||||
Shared helpers for LiveView tests.
|
||||
|
||||
These helpers sit alongside PhoenixTest and Phoenix.LiveViewTest so tests can
|
||||
keep PhoenixTest sessions in the pipeline while still reaching for lower-level
|
||||
LiveView interactions when PhoenixTest does not cover them directly.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Escapes text for assertions against rendered HTML.
|
||||
"""
|
||||
def escape(string) do
|
||||
LazyHTML.html_escape(string)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Waits for LiveView async work to finish.
|
||||
|
||||
Accepts either a PhoenixTest session, returning the session for continued
|
||||
piping, or a raw LiveView view/element, returning the rendered HTML from
|
||||
`Phoenix.LiveViewTest.render_async/2`.
|
||||
"""
|
||||
def render_async(
|
||||
session_or_view,
|
||||
timeout \\ Application.fetch_env!(:ex_unit, :assert_receive_timeout)
|
||||
)
|
||||
|
||||
def render_async(%{view: %Phoenix.LiveViewTest.View{}} = session, timeout) do
|
||||
PhoenixTest.unwrap(session, &Phoenix.LiveViewTest.render_async(&1, timeout))
|
||||
end
|
||||
|
||||
def render_async(view_or_element, timeout) do
|
||||
Phoenix.LiveViewTest.render_async(view_or_element, timeout)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Dispatches a hook event to an element inside a PhoenixTest session.
|
||||
"""
|
||||
def trigger_hook(session, selector, hook, params \\ %{}) do
|
||||
session
|
||||
|> PhoenixTest.unwrap(fn view ->
|
||||
|
||||
Reference in New Issue
Block a user