diff --git a/lib/jsdom/living/nodes/Element-impl.js b/lib/jsdom/living/nodes/Element-impl.js index 3db0cb2071..bfc30bba4d 100644 --- a/lib/jsdom/living/nodes/Element-impl.js +++ b/lib/jsdom/living/nodes/Element-impl.js @@ -408,6 +408,11 @@ class ElementImpl extends NodeImpl { } } } + + closest(selectors) { + const matcher = addNwsapi(this); + return matcher.closest(selectors, idlUtils.wrapperForImpl(this)); + } } mixin(ElementImpl.prototype, NonDocumentTypeChildNode.prototype); diff --git a/lib/jsdom/living/nodes/Element.webidl b/lib/jsdom/living/nodes/Element.webidl index dbe5628854..1660a219aa 100644 --- a/lib/jsdom/living/nodes/Element.webidl +++ b/lib/jsdom/living/nodes/Element.webidl @@ -31,7 +31,7 @@ interface Element : Node { // ShadowRoot attachShadow(ShadowRootInit init); // readonly attribute ShadowRoot? shadowRoot; -// Element? closest(DOMString selectors); + Element? closest(DOMString selectors); boolean matches(DOMString selectors); boolean webkitMatchesSelector(DOMString selectors); // historical alias of .matches diff --git a/test/web-platform-tests/to-run.yaml b/test/web-platform-tests/to-run.yaml index c7570bbcb0..f02a55702a 100644 --- a/test/web-platform-tests/to-run.yaml +++ b/test/web-platform-tests/to-run.yaml @@ -138,7 +138,7 @@ Element-childElementCount-dynamic-add-xhtml.xhtml: [fail, Unknown] Element-childElementCount-dynamic-remove-xhtml.xhtml: [fail, Unknown] Element-childElementCount-nochild-xhtml.xhtml: [fail, Unknown] Element-childElementCount-xhtml.xhtml: [fail, Unknown] -Element-closest.html: [fail, Not implemented] +Element-closest.html: [fail, :has is not supported (by all major browsers as well)] Element-firstElementChild-entity-xhtml.xhtml: [fail, Unknown] Element-firstElementChild-namespace-xhtml.xhtml: [fail, Unknown] Element-firstElementChild-xhtml.xhtml: [fail, Unknown] diff --git a/test/web-platform-tests/to-upstream/dom/nodes/Element-closest-dont-upstream.html b/test/web-platform-tests/to-upstream/dom/nodes/Element-closest-dont-upstream.html new file mode 100644 index 0000000000..7b50e0fc81 --- /dev/null +++ b/test/web-platform-tests/to-upstream/dom/nodes/Element-closest-dont-upstream.html @@ -0,0 +1,76 @@ + + +Test for Element.closest + + + + +
+