I created some svg element and want to determine its size with
svgElement.getBoundingClientRect()
My code works if the svgElement is appended to the document with
document.body.appendChild(svgElement)
and if I run the code in the browser (google chrome).
However, while testing with nodejs and jest, the width and the height of the resulting bounding rect are always zero.
=>What can I do to correctly run the code with nodejs?
I created some svg element and want to determine its size with
svgElement.getBoundingClientRect()
My code works if the svgElement is appended to the document with
document.body.appendChild(svgElement)
and if I run the code in the browser (google chrome).
However, while testing with nodejs and jest, the width and the height of the resulting bounding rect are always zero.
=>What can I do to correctly run the code with nodejs?
Share Improve this question edited Mar 23, 2020 at 16:55 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Mar 23, 2020 at 15:22 StefanStefan 12.4k9 gold badges77 silver badges139 bronze badges1 Answer
Reset to default 7Nodejs uses jsdom and getBoundingClientRect
is only implemented to return the right properties, but not the right values.
Also see https://github./jsdom/jsdom/issues/653
For the tests the method getBoundingClientRect
should be mocked, for example with:
spyOn(svgElement,'getBoundingClientRect').and.returnValue({
width: 10,
height: 10,
top: 0,
left: 0,
right: 10,
bottom: 10
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744847574a4596935.html
评论列表(0条)