You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I alter height/width element properties in jsdom? I don't see any setters and simply applying a value to a selected property won't work.
I realize this is not what we would do within a regular browser environment, but jsdom doesn't seem to implement any kind of height/width properties by itself. Simply adding elements to the jsdom constructor should increase height/width properties of the document.
I also found this "solution", but it only extends to document.documentElement and does not update any other nodes (body, p#content).
Minimal reproduction case
const{JSDOM}=require("jsdom");constdom=newJSDOM('<!DOCTYPE html><p id="content">Some Elem with height </p>');//without alterationconsole.log(dom.window.document.body.querySelector('#content').clientHeight);// 0 There is no real height property//simply trying to assign a valuedom.window.document.documentElement.clientHeight=1234;console.log(dom.window.document.documentElement.clientHeight);// 0//using definePropertyObject.defineProperty(dom.window.HTMLHtmlElement.prototype,'clientWidth',{value: 1234});console.log(dom.window.document.documentElement.clientWidth)// 1234console.log(dom.window.document.body.clientWidth)// 0 console.log(dom.window.document.documentElement.querySelector('#content').clientWidth)// 0
The text was updated successfully, but these errors were encountered:
Simply adding elements to the jsdom constructor should increase height/width properties of the document.
Doing this would require implementing a layout system, which is not currently in our plans. The best you can do is use defineProperty to supply fake values. But, if you really want to get layed-out coordinates, you may be best off with a true headless browser, not with jsdom.
How can I alter height/width element properties in jsdom? I don't see any setters and simply applying a value to a selected property won't work.
I realize this is not what we would do within a regular browser environment, but jsdom doesn't seem to implement any kind of height/width properties by itself. Simply adding elements to the jsdom constructor should increase height/width properties of the document.
I also found this "solution", but it only extends to document.documentElement and does not update any other nodes (body, p#content).
Minimal reproduction case
The text was updated successfully, but these errors were encountered: