Skip to content

Commit

Permalink
Add unit test for using error prop as a function in Document
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Oct 24, 2022
1 parent 4558659 commit 458a033
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Document.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,29 @@ describe('Document', () => {
restoreConsole();
});

it('renders custom error message when failed to load a document', async () => {
it('renders custom error message when failed to load a document and error prop is given', async () => {
const { func: onLoadError, promise: onLoadErrorPromise } = makeAsyncCallback();
const failingPdf = 'data:application/pdf;base64,abcdef';

muteConsole();

const { container } = render(
<Document error="Error" file={failingPdf} onLoadError={onLoadError} />,
);

expect.assertions(2);

await onLoadErrorPromise;

const error = container.querySelector('.react-pdf__message');

expect(error).toBeInTheDocument();
expect(error).toHaveTextContent('Error');

restoreConsole();
});

it('renders custom error message when failed to load a document and error prop is given as a function', async () => {
const { func: onLoadError, promise: onLoadErrorPromise } = makeAsyncCallback();
const failingPdf = 'data:application/pdf;base64,abcdef';

Expand Down

0 comments on commit 458a033

Please sign in to comment.