Answer the question
In order to leave comments, you need to log in
How to get coordinates using getBoundingClientRect in node.js environment?
Hello guys! Maybe someone knows, tell me please, the method does not work getBoundingClientRect
in node.js
, that is, through Mocha
.
I explain: I want to write a simple test for some 2 elements (nodes). I use mocha
and use to build a house-tree jsdom-global
.
It goes something like this:
require('jsdom-global')(`
<!doctype html>
<html>
<body>
<div class="main">
<button>
<span>Нажми</span>
</button>
</div>
<div>
<div class="main__section">
<ul>
<li>Пункт 1</li>
<li>Пункт 2</li>
</ul>
</div>
</div>
</body>
</html>
`);
const mainNode = document.querySelector('.main');
mainNode.style.width = 100;
mainNode.style.height = 50;
mainNode.style.top = '200px';
mainNode.style.right = '300px';
mainNode.style.bottom = '25px';
mainNode.style.left = '100px';
window.getComputedStyle(mainNode)
- styles are applied mainNode.getBoundingClientRect()
- it returns everything by zero (((
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question