How to unit test react-pdf renderer PDFDownloadLink loading/error?

1k Views Asked by At

I have implemented a PDFDownloadLink link to download my PDF with the internal error/loading state used to conditionally render different messages.

The problem now is... I don't know how to unit test this.

Before I introduced the inner section and just had a static message, I could easily get around in the test by outputting a children usage in the mock, but now that obviously doesn't work...

PDFDownloadLink
    document={<MyPdf />}
    fileName="yourPDF.pdf"
>
    {({ loading, error }) => {
       if loading //do loading message
       if error //do error message

Mock in test

jest.mock('@react-pdf/renderer', () => ({
    PDFDownloadLink: jest.fn(({children}) => <div>{children}</div>),
    ...

Any tips?

0

There are 0 best solutions below