Implement `Document` `elementFromPoint()`
TypeError: Object [object HTMLDocument] has no method 'elementFromPoint'
document.elementFromPoint is not implemented by jsdom. Raising it as an issue cos it was raised elsewhere https://github.com/inikulin/parse5/issues/50
It's impossible to implement it in jsdom currently, because it requires layouting.
It could at least be stubbed, though.
In that case feature detection wouldn't work anymore - you can also easily stub it in the created callback.
I'm working on a library (built with Node on server side) that conducts accessibility (A11y) audits on HTML, for which one of the utils has code to check if an element is offscreen, in scrollable area, outside the viewport and various such stuff.
document.elementFromPoint was an easy way to calculate it. The issue began when I started writing server side test cases for the utils, via JSDOM. It wasn't supporting it.
Yeah that will realistically never work in JSDOM. No layout engine = no screen, no scrolling, etc.
For your needs I'd recommend something like phantom.
It's interesting why some angular unit tests in my repo have been passing with jest 22. They test code which uses this method. Now with jest 27, I hit this issue.
It is unfortunate today that using document.elementFromPoint causes an error given that document.elementFromPoint is an old and stable API.
I propose that document.elementFromPoint be added to jsdom, and that the function would just return null, as null is a valid return of the function. Making this change would mean that calls to document.elementFromPoint would no longer error
document.elementFromPoint(x: number, y: number): Element | null
Implementation:
document.elementFromPoint = function elementFromPoint() {
return null;
}
I am happy to raise a pull request @domenic if it is helpful