React-pdf: ReactPDF won't pass the test

Created on 10 Aug 2017  路  7Comments  路  Source: wojtekmaj/react-pdf

The new version is working perfectly in the project, but it does not pass the test for me.
here are versions:

"babel-jest": "^20.0.3",
"jest": "20.1.0-alpha.3",
"react-pdf": "^1.8.3",

here is the test code.
P.S: PDFViewer has the ReactPDF inside.

import React from 'react';
import ReactDOM from 'react-dom';
import PDFViewer from './index';
import { wrapInMuiThemeProvider } from '../../util';
import injectTapEventPlugin from 'react-tap-event-plugin';

injectTapEventPlugin();

it('renders without crashing', () => {
  const div = document.createElement('div');
  const elem = (<PDFViewer file={'https://rawgit.com/nnarhinen/react-pdf/master/sample/sample.pdf'} />);
  ReactDOM.render(wrapInMuiThemeProvider(elem), div);
});

and here is the complete result:

No PDFJS.workerSrc specified

      at getWorkerSrc (node_modules/pdfjs-dist/build/pdf.js:2494:11)
      at loader (node_modules/pdfjs-dist/build/pdf.js:2504:29)
      at setupFakeWorkerGlobal (node_modules/pdfjs-dist/build/pdf.js:2508:5)
      at Object.PDFWorker_setupFakeWorker [as _setupFakeWorker] (node_modules/pdfjs-dist/build/pdf.js:2644:7)
      at Object.PDFWorker_initialize [as _initialize] (node_modules/pdfjs-dist/build/pdf.js:2635:12)
      at Object.PDFWorker (node_modules/pdfjs-dist/build/pdf.js:2532:10)
      at Object.getDocument (node_modules/pdfjs-dist/build/pdf.js:1923:60)
      at ReactPDF.loadDocument (node_modules/react-pdf/build/react-pdf.js:196:36)
      at ReactPDF.handleFileLoad (node_modules/react-pdf/build/react-pdf.js:140:23)
      at ReactPDF.componentDidMount (node_modules/react-pdf/build/react-pdf.js:43:12)
      at node_modules/react-dom/lib/ReactCompositeComponent.js:265:25
      at measureLifeCyclePerf (node_modules/react-dom/lib/ReactCompositeComponent.js:75:12)
      at node_modules/react-dom/lib/ReactCompositeComponent.js:264:11
      at CallbackQueue.notifyAll (node_modules/react-dom/lib/CallbackQueue.js:76:22)
      at ReactReconcileTransaction.close (node_modules/react-dom/lib/ReactReconcileTransaction.js:80:26)
      at ReactReconcileTransaction.closeAll (node_modules/react-dom/lib/Transaction.js:206:25)
      at ReactReconcileTransaction.perform (node_modules/react-dom/lib/Transaction.js:153:16)
      at batchedMountComponentIntoNode (node_modules/react-dom/lib/ReactMount.js:126:15)
      at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-dom/lib/Transaction.js:140:20)
      at Object.batchedUpdates (node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js:62:26)
      at Object.batchedUpdates (node_modules/react-dom/lib/ReactUpdates.js:97:27)
      at Object._renderNewRootComponent (node_modules/react-dom/lib/ReactMount.js:320:18)
      at Object._renderSubtreeIntoContainer (node_modules/react-dom/lib/ReactMount.js:401:32)
      at Object.render (node_modules/react-dom/lib/ReactMount.js:422:23)
      at Object.<anonymous>.it (src/RegLib/PDFViewer/PDFViewer.test.js:12:48)
      at process._tickCallback (internal/process/next_tick.js:103:7)

Is it a bug or a problem of mine?
Thanks.

question

All 7 comments

Hey there! What is the last version you haven't had a problem with?

On a side note, check out the new 2.0.0 beta version. It's far more advanced, faster and shouldn't have the issue you're talking about. :)

Thanks for the prompt response.
The previous version was 1.6.1

I tried the new beta version, but It won't pass the test and I got this error:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check your code at index.jsx:198.
          in PDFViewer (at PDFViewer.test.jsx:12)
          in MuiThemeProvider (at index.jsx:6)

The index.jsx:198 is where I used ReactPDF.

The reason you have encountered the error is because 2.0 introduces breaking changes. Hence the major version bump. You will need to make slight modifications to your code to make it work, but I think it's worth it.

I really hope the new README.md is clear and you won't have problems with it. Should you have any issues with it don't hesitate to share your feedback!

Thanks a lot. I did not aware of major changes. It seems the new version is more powerful and has better performance. I should try it.

Back to discussing 1.8.3. I've analyzed what happened between versions (already my mind is in 2.x branch...) and here's what happened:

workerSrc in 1.6.1 was indeed specified, but in an incorrect way, resulting in a worker file being loaded and later not used by the project at all. This could have caused performance issues.

This was corrected in later updates, but to make it work, it requires small changes from developers. If you're using webpack, it's super easy - you just import the component using specially crafted enyry - import ReactPDF from 'react-pdf/build/entry.webpack'; and you're good to go. If you are not using Webpack, you will have a little more trouble, but that was (I hope!) vastly improved, well documented and explained in 2.0's README.

Hey @saman, for your information - v2.0.0 (non-beta) just went live!

Thanks for informing me.
I rewrote my code and Implemented [email protected]. It works perfectly at this time. I wanted to say thank you. If I got any problem and ideas I will inform you.

Thanks again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zambony picture zambony  路  3Comments

herneli picture herneli  路  3Comments

Solitaryo picture Solitaryo  路  5Comments

joepio picture joepio  路  3Comments

Kerumen picture Kerumen  路  3Comments