Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npm test fails #35

Closed
mattermoran opened this issue Aug 28, 2017 · 7 comments
Closed

Npm test fails #35

mattermoran opened this issue Aug 28, 2017 · 7 comments

Comments

@mattermoran
Copy link

Running npm test always fails.

` FAIL src/App.test.js
● renders without crashing

ReferenceError: Worker is not defined
  
  at Reader.componentDidMount (node_modules/react-qr-reader/lib/index.js:61:25)
  at node_modules/react-dom/lib/ReactCompositeComponent.js:264:25
  at measureLifeCyclePerf (node_modules/react-dom/lib/ReactCompositeComponent.js:75:12)
  at node_modules/react-dom/lib/ReactCompositeComponent.js:263: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:209:25)
  at ReactReconcileTransaction.perform (node_modules/react-dom/lib/Transaction.js:156:16)
  at batchedMountComponentIntoNode (node_modules/react-dom/lib/ReactMount.js:126:15)
  at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-dom/lib/Transaction.js:143: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:319: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/App.test.js:8:22)
      at Promise (<anonymous>)
  at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
      at <anonymous>
  at process._tickCallback (internal/process/next_tick.js:188:7)

✕ renders without crashing (31ms)

Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.75s
Ran all test suites.
`

@JodusNodus
Copy link
Owner

Not sure what test you are running as there is no test included in the repo. Testing is done manually since it needs a webcam and stuff. Mocking all that would be more work than testing it manual every release.

@mattermoran
Copy link
Author

Just tried recreating this on the new project.
So first i created new project using create-react-app.
Run npm test and get this:
screen shot 2017-08-28 at 19 41 17
Then i install react-qr-reader and use code from the example. Now if I try npm test i get this:
screen shot 2017-08-28 at 19 47 16

Here's the code from npm test:

`import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(, div);
});`

@JodusNodus
Copy link
Owner

Aah i see, react-qr-reader uses web workers. To create the web worker new Worker(url) is used. You could mock that but the module makes use of the web worker extensibly & other browser API's like WebRTC. It would be much easier to not test the component.

@mattermoran
Copy link
Author

How to ignore it so test passes?

@JodusNodus
Copy link
Owner

Use shallow rendering (http://airbnb.io/enzyme/docs/api/shallow.html). This way the QR reader component shouldn't be rendered.

@mattermoran
Copy link
Author

alright, thank a lot for a quick response and the module. It works great for my app!

@JodusNodus
Copy link
Owner

Happy to help, great to hear 👍 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants