I'm writing unit testing and e2e testing for a popover component in React. I should check if the popup is hidden when I click outside the component. I'm using Jest + Enzyme for unit testing and Cypress for e2e testing. Does anybody know how to do this?
I've tried as follows in cypress.
cy.get('[data-test-id="popover-container"]').click(-20, -20, {force: true});
But the clicked point is actually outside of the popup window, but it doesn't work.
react-tiny-popover
library is used to show the popover as follows:
<Popover
content={({ position, targetRect, popoverRect }) => (
<ArrowContainer
position={position}
targetRect={targetRect}
popoverRect={popoverRect}
arrowColor={'#ccc'}
arrowSize={10}
>
<div data-test-id="popover-container">
<Content/>
</div>
</ArrowContainer>
)}
isOpen={visible}
onClickOutside={() => hideOnOutsideClick && setVisible(false)}
position={position}
>
<div onClick={() => setVisible(!visible)}>{children}</div>
</Popover>