diff --git a/config/test.exs b/config/test.exs index 48793de45..3f21df075 100644 --- a/config/test.exs +++ b/config/test.exs @@ -3,4 +3,9 @@ import Config config :logger, :level, :debug config :logger, :default_handler, false +# we still support 1.14, silence logs in tests +if Version.match?(System.version(), "< 1.15.0") do + config :logger, :backends, [] +end + config :phoenix_live_view, enable_expensive_runtime_checks: true diff --git a/test/phoenix_live_view/integrations/live_view_test.exs b/test/phoenix_live_view/integrations/live_view_test.exs index 0a94bc32b..56974b502 100644 --- a/test/phoenix_live_view/integrations/live_view_test.exs +++ b/test/phoenix_live_view/integrations/live_view_test.exs @@ -155,26 +155,30 @@ defmodule Phoenix.LiveView.LiveViewTest do test "raises for duplicate ids when on_error: :raise", %{conn: conn} do Process.flag(:trap_exit, true) - {:ok, view, _html} = live(conn, "/duplicate-id", on_error: :raise) - {{exception, _}, _} = catch_exit(render(view)) + fun = fn -> + {:ok, view, _html} = live(conn, "/duplicate-id", on_error: :raise) + render(view) + end + assert catch_exit(fun.()) + assert_receive {:EXIT, _pid, {exception, _}} assert Exception.message(exception) =~ "Duplicate id found while testing LiveView: a" - assert_receive {:EXIT, _, _} end test "raises for duplicate components when on_error: :raise", %{conn: conn} do Process.flag(:trap_exit, true) - {:ok, view, _html} = live(conn, "/dynamic-duplicate-component", on_error: :raise) - view |> element("button", "Toggle duplicate LC") |> render_click() =~ "I am LiveComponent2" - - {{exception, _}, _} = catch_exit(render(view)) + fun = fn -> + {:ok, view, _html} = live(conn, "/dynamic-duplicate-component", on_error: :raise) + view |> element("button", "Toggle duplicate LC") |> render_click() + render(view) + end + assert catch_exit(fun.()) + assert_receive {:EXIT, _pid, {exception, _}} message = Exception.message(exception) assert message =~ "Duplicate live component found while testing LiveView:" assert message =~ "I am LiveComponent2" refute message =~ "I am a LC inside nested LV" - - assert_receive {:EXIT, _, _} end end @@ -417,34 +421,43 @@ defmodule Phoenix.LiveView.LiveViewTest do test "raises for duplicate ids when on_error: raise" do Process.flag(:trap_exit, true) - {:ok, view, _html} = - live_isolated(Phoenix.ConnTest.build_conn(), Phoenix.LiveViewTest.Support.DuplicateIdLive, - on_error: :raise - ) + fun = fn -> + {:ok, view, _html} = + live_isolated( + Phoenix.ConnTest.build_conn(), + Phoenix.LiveViewTest.Support.DuplicateIdLive, + on_error: :raise + ) + # errors are detected asynchronously, so we need to render again for the message to be processed + render(view) + end - {{exception, _}, _} = catch_exit(render(view)) + assert catch_exit(fun.()) + assert_receive {:EXIT, _, {exception, _}} assert Exception.message(exception) =~ "Duplicate id found while testing LiveView: a" - assert_receive {:EXIT, _, _} end test "raises for duplicate components when on_error: raise" do Process.flag(:trap_exit, true) - {:ok, view, _html} = - live_isolated( - Phoenix.ConnTest.build_conn(), - Phoenix.LiveViewTest.Support.DynamicDuplicateComponentLive, - on_error: :raise - ) + fun = fn -> + {:ok, view, _html} = + live_isolated( + Phoenix.ConnTest.build_conn(), + Phoenix.LiveViewTest.Support.DynamicDuplicateComponentLive, + on_error: :raise + ) + view |> element("button", "Toggle duplicate LC") |> render_click() + render(view) + end - view |> element("button", "Toggle duplicate LC") |> render_click() =~ "I am LiveComponent2" + # errors are detected asynchronously, so we need to render again for the message to be processed + assert catch_exit(fun.()) - {{exception, _}, _} = catch_exit(render(view)) + assert_receive {:EXIT, _, {exception, _}} assert Exception.message(exception) =~ "Duplicate live component found while testing LiveView:" - - assert_receive {:EXIT, _, _} end end