File tree Expand file tree Collapse file tree 4 files changed +35
-26
lines changed
lib/phoenix_live_view/test Expand file tree Collapse file tree 4 files changed +35
-26
lines changed Original file line number Diff line number Diff line change @@ -44,17 +44,19 @@ defmodule Phoenix.LiveViewTest.DOM do
4444 case Floki . attribute ( node , "id" ) do
4545 [ id ] ->
4646 if MapSet . member? ( ids , id ) do
47- raise """
48- Duplicate id found: #{ id }
47+ IO . warn ( """
48+ Duplicate id found while testing LiveView: #{ id }
49+
50+ #{ inspect_html ( node ) }
4951
5052 LiveView requires that all elements have unique ids, duplicate IDs will cause
5153 undefined behavior at runtime, as DOM patching will not be able to target the correct
5254 elements.
53- """
54- else
55- detect_duplicate_ids ( children , MapSet . put ( ids , id ) )
55+ """ )
5656 end
5757
58+ detect_duplicate_ids ( children , MapSet . put ( ids , id ) )
59+
5860 _ ->
5961 detect_duplicate_ids ( children , ids )
6062 end
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ defmodule Phoenix.LiveView.NestedTest do
147147 :ok = GenServer . call ( view . pid , { :dynamic_child , :static } )
148148
149149 assert Exception . format ( :exit , catch_exit ( render ( view ) ) ) =~
150- "Duplicate id found: static"
150+ "expected selector \" # static\" to return a single element, but got 2 "
151151 end
152152
153153 describe "navigation helpers" do
Original file line number Diff line number Diff line change @@ -292,24 +292,4 @@ defmodule Phoenix.LiveViewTest.DOMTest do
292292 % { s: "bar" , streams: [ ] }
293293 end
294294 end
295-
296- describe "parse" do
297- test "detects duplicate ids" do
298- assert_raise RuntimeError , fn ->
299- DOM . parse ( """
300- <div id="foo">
301- <div id="foo"></div>
302- </div>
303- """ )
304- end
305- end
306-
307- test "handles declarations (issue #3594)" do
308- assert DOM . parse ( """
309- <div id="foo">
310- <?xml version="1.0" standalone="yes"?>
311- </div>
312- """ )
313- end
314- end
315295end
Original file line number Diff line number Diff line change 1+ defmodule Phoenix.LiveViewTest.DOMWarnTest do
2+ use ExUnit.Case , async: false
3+
4+ import ExUnit.CaptureIO
5+
6+ alias Phoenix.LiveViewTest.DOM
7+
8+ describe "parse" do
9+ test "detects duplicate ids" do
10+ assert capture_io ( :stderr , fn ->
11+ DOM . parse ( """
12+ <div id="foo">
13+ <div id="foo"></div>
14+ </div>
15+ """ )
16+ end ) =~ "Duplicate id found while testing LiveView"
17+ end
18+
19+ test "handles declarations (issue #3594)" do
20+ assert DOM . parse ( """
21+ <div id="foo">
22+ <?xml version="1.0" standalone="yes"?>
23+ </div>
24+ """ )
25+ end
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments