I am trying to test whether a component – say dynamicallyPositionedElement – has the correct position or not.
The position of the dynamicallyPositionedElement is set in the callback of an event listener (keydown in my case), which is triggered on onkeydown
event registered on an element – say eventEmanantingElement.
So, basically to set the position of the dynamicallyPositionedElement, we get
the position of the eventEmanantingElement first and set the position of dynamicallyPositionedElement to the value of the position of eventEmanantingElement .
So, in the callback of onkeydown
event we do,
setDynamicallyPositionedElement({
left: e.currentTarget.offsetLeft, // currentTarget is the eventEmanatingElement
width: e?.currentTarget.offsetWidth,
});
How can we test such a functionality? I am using React Testing Library.