Failing test using jest on import { PDFDownloadLink }
See original GitHub issueDescribe the bug
I am using PDFDownloadLink
to create a PDF and download it when I click on a button. Everything is working fine, except when I run my tests using jest. I haven’t implemented any test on the PDF component itself, jest is blocked on the following import:
ReferenceError: _a is not defined
import { PDFDownloadLink } from '@react-pdf/renderer'
Thank you in advance for your time!
Expected behavior
Pass the tests while importing PDFDownloadLink
.
Screenshots
Desktop:
- OS: MacOS
- Browser: chrome
- React-pdf version: 1.6.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top Results From Across the Web
react-pdf - npm
Import by adding import { Document } from 'react-pdf' . ... It is tested with the latest versions of Chrome, Edge, Safari, Firefox,...
Read more >Unable to import module in my Jest test file - Stack Overflow
I am importing one such service in my unit test. I am using jest for unit testing. Without import, test is working fine....
Read more >Testing React Apps - Jest
At Facebook, we use Jest to test React applications. ... When a snapshot test fails, you need to inspect whether it is an...
Read more >Setup - Testing Library
In these docs we'll demonstrate configuring Jest, but you should be able to ... import { render, fireEvent } from '@testing-library/react';
Read more >Testing Recipes - React
This page assumes you're using Jest as a test runner. ... hello.js import React from "react"; export default function Hello(props) { if (props.name) ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So this doesn’t necessarily fix this issue, but if your Jest tests are failing after adding the
PDFDownloadLink
to your component, you can mock it out to keep everything working. If you strictly want your tests to keep working, just do something like this:and if you care about testing the children that are being passed into the
PDFDownloadLink
, you can still render them with something like this:Just mock everything until it passes 😅
I also have a similar issue with testing this using Jest/React-Testing-Library. Below is the Error I receive.