Skip to content

Commit 7673a7e

Browse files
author
spicychickensauce
committed
Don't include self in ancestor_chain
1 parent 323deb7 commit 7673a7e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

test/lazy_html_test.exs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,26 @@ defmodule LazyHTMLTest do
299299
end
300300

301301
defp ancestor_chain(node) do
302+
parent = LazyHTML.parent_node(node)
302303
if Enum.count(node) == 0 do
303304
[]
304305
else
305-
ancestor_chain(LazyHTML.parent_node(node)) ++ LazyHTML.tag(node)
306+
ancestor_chain(parent) ++ LazyHTML.tag(parent)
306307
end
307308
end
308309

309310
test "last parent node is <html> if instantiated via from_document and similar" do
310311
lazy_html = LazyHTML.from_document("<html><body><div>root</div></body></html>")
311-
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["html", "body", "div"]
312+
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["html", "body"]
312313

313314
lazy_html = LazyHTML.from_fragment("<div>root</div>")
314-
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["div"]
315+
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == []
315316

316317
lazy_html = LazyHTML.from_tree([{"div", [], []}])
317-
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["div"]
318+
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == []
318319

319320
lazy_html = LazyHTML.from_tree([{"html", [], [{"body", [], [{"div", [], []}]}]}])
320-
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["html", "body", "div"]
321+
assert lazy_html |> LazyHTML.query("div") |> ancestor_chain() == ["html", "body"]
321322
end
322323
end
323324

0 commit comments

Comments
 (0)