Are there any test to this react functional component in Jest?
The problem is that window print open an iframe when I start this component with modalIsVisible active.
type SixLabelReportType = {
labels: LabelProps[];
modalIsVisible: boolean;
setModalIsVisible: Dispatch<SetStateAction<boolean>>;
};
const SixLabelReport: React.FC<SixLabelReportType> = (
params: SixLabelReportType
) => {
const { labels, modalIsVisible, setModalIsVisible } = params;
useEffect(() => {
if (modalIsVisible) {
window.print();
setModalIsVisible(false);
}
}, [modalIsVisible]);
return (
<S.Modal show={modalIsVisible} data-testid='six-label-report-modal'>
<S.Container data-testid='six-label-report-container'>
{labels.map((label, idx) => {
const { deliveryData, recipientData, senderData } = label;
return (
<Label
key={idx}
deliveryData={deliveryData}
recipientData={recipientData}
senderData={senderData}
data-testid='six-label-report-label'
/>
);
})}
</S.Container>
</S.Modal>
);
};
Just spy on window.open
const spy = jest.spyOn(window, 'open');
expect(spy).toHaveBeenCalled();