How to setup worker in unit test in Create-React-App?
See original GitHub issueWhat are you trying to achieve? Please describe.
Run a test that loads a pdf from local file in a CRA app.
Describe solutions you’ve tried
I have tried putting the following at the top of my unit test file
import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
but i get the following error
setting up fake worker failed: "Cannot find module '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.5.207/pdf.worker.min.js' from '../../node_modules/pdfjs-dist/build/pdf.js'".
Environment
“react-scripts”: “^4.0.1”, “react-pdf”: “^5.1.0”, “react”: “^17.0.1”,
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Running Tests | Create React App
We recommend to put the test files (or __tests__ folders) next to the code they are testing so that relative imports appear shorter....
Read more >How To Test a React App with Jest and React Testing Library
Step 1 — Setting up the Project. In this step, you will clone a sample project and launch the test suite. The sample...
Read more >How To Test Your React Apps With The React Testing Library
Open a terminal and copy and run the below command. # start new react project and start the server npx create-react-app start-rtl &&...
Read more >How to setup unit tests with Create React App, Mocha and ...
2. Install Mocha as a dev dependency, the test engine · 3. Install Chai-Enzyme · 4. Install · 5. Configure Babel · 6....
Read more >Testing React Components with Testing Library and Mock ...
Testing React Components with Testing Library and Mock Service Worker · npm install msw. Once installed, we need to create some directories. ·...
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
This solution has worked for me as well, the only thing I had to change though is this:
I.e. removed
$
cause I have:Well the above did indeed work, to some extend at least, for me as well. But now I’m getting this issue: