Files
sousa-gecko/testing/web-platform/tests/dom/traversal/TreeWalker-nextNode-detached-currentNode.window.js
T
Anne van Kesteren cfa7025fc1 Bug 2042847 [wpt PR 60053] - DOM: more TreeWalker nextNode() coverage, a=testonly
Automatic update from web-platform-tests
DOM: more TreeWalker nextNode() coverage

Complements https://github.com/whatwg/dom/pull/1433.
--

wpt-commits: d2cf5e8afc8df9f64481ce9709ff7c1afb34ed7c
wpt-pr: 60053
2026-05-29 16:00:15 +00:00

28 lines
1.2 KiB
JavaScript

test(() => {
const detached = document.createElement("div");
const walker = document.createTreeWalker(document, 0, null);
walker.currentNode = detached;
assert_equals(walker.nextNode(), null);
}, "nextNode() returns null when currentNode is a detached element with no descendants and whatToShow does not match it");
test(() => {
const detached = document.createElement("div");
detached.appendChild(document.createElement("span"));
const walker = document.createTreeWalker(document, NodeFilter.SHOW_ELEMENT, null);
walker.currentNode = detached;
assert_equals(walker.nextNode(), detached.firstChild);
assert_equals(walker.nextNode(), null);
}, "nextNode() returns null after exhausting a detached subtree");
test(() => {
const template = document.createElement("template");
template.innerHTML = "text<div></div>text";
const walker = document.createTreeWalker(
document,
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT,
null);
walker.currentNode = template.content;
assert_equals(walker.nextNode(), template.content.children[0]);
assert_equals(walker.nextNode(), null);
}, "nextNode() terminates when iterating over template.content not under the walker's root");