-
Notifications
You must be signed in to change notification settings - Fork 953
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test duplicate id / component errors
- Loading branch information
Showing
6 changed files
with
322 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
test/phoenix_live_view/integrations/live_view_test_warnings_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
defmodule Phoenix.LiveView.LiveViewTestWarningsTest do | ||
use ExUnit.Case, async: false | ||
|
||
import ExUnit.CaptureIO | ||
|
||
import Phoenix.ConnTest | ||
import Phoenix.LiveViewTest | ||
|
||
alias Phoenix.LiveViewTest.Support.Endpoint | ||
|
||
@endpoint Endpoint | ||
|
||
describe "live" do | ||
test "warns for duplicate ids when on_error: warn" do | ||
conn = Plug.Test.init_test_session(Phoenix.ConnTest.build_conn(), %{}) | ||
conn = get(conn, "/duplicate-id") | ||
|
||
Process.flag(:trap_exit, true) | ||
|
||
assert capture_io(:stderr, fn -> | ||
{:ok, view, _html} = live(conn, nil, on_error: :warn) | ||
render(view) | ||
end) =~ | ||
"Duplicate id found while testing LiveView: a" | ||
|
||
refute_receive {:EXIT, _, _} | ||
end | ||
|
||
test "warns for duplicate component when on_error: warn" do | ||
conn = Plug.Test.init_test_session(Phoenix.ConnTest.build_conn(), %{}) | ||
conn = get(conn, "/dynamic-duplicate-component") | ||
|
||
Process.flag(:trap_exit, true) | ||
|
||
assert capture_io(:stderr, fn -> | ||
{:ok, view, _html} = live(conn, nil, on_error: :warn) | ||
|
||
view |> element("button", "Toggle duplicate LC") |> render_click() =~ | ||
"I am LiveComponent2" | ||
|
||
render(view) | ||
end) =~ | ||
"Duplicate live component found while testing LiveView:" | ||
|
||
refute_receive {:EXIT, _, _} | ||
end | ||
end | ||
|
||
describe "live_isolated" do | ||
test "warns for duplicate ids when on_error: warn" do | ||
Process.flag(:trap_exit, true) | ||
|
||
assert capture_io(:stderr, fn -> | ||
{:ok, view, _html} = | ||
live_isolated( | ||
Phoenix.ConnTest.build_conn(), | ||
Phoenix.LiveViewTest.Support.DuplicateIdLive, | ||
on_error: :warn | ||
) | ||
|
||
render(view) | ||
end) =~ | ||
"Duplicate id found while testing LiveView: a" | ||
|
||
refute_receive {:EXIT, _, _} | ||
end | ||
|
||
test "warns for duplicate component when on_error: warn" do | ||
Process.flag(:trap_exit, true) | ||
|
||
assert capture_io(:stderr, fn -> | ||
{:ok, view, _html} = | ||
live_isolated( | ||
Phoenix.ConnTest.build_conn(), | ||
Phoenix.LiveViewTest.Support.DynamicDuplicateComponentLive, | ||
on_error: :warn | ||
) | ||
|
||
view |> element("button", "Toggle duplicate LC") |> render_click() =~ | ||
"I am LiveComponent2" | ||
|
||
render(view) | ||
end) =~ | ||
"Duplicate live component found while testing LiveView:" | ||
|
||
refute_receive {:EXIT, _, _} | ||
end | ||
end | ||
end |
Oops, something went wrong.