lundi 3 septembre 2018

Troubles configuring jest+enzyme with create-react-app

I am trying to configure testing frameworks to test react components but no matter what I try I get some errors. Steps to reproduce:

  1. create-react-app react-test
  2. npm i enzyme enzyme-adapter-react-16 react-test-renderer
  3. Inside src folder touch setupTests.js and past the following code into it

    import { configure } from 'enzyme';
    
    import Adapter from 'enzyme-adapter-react-16';
    
    configure({ adapter: new Adapter() });
    
    
  4. npm run test with either default create-react-app test or shallow-rendering test

I get this error in terminal

react-component-testing@0.1.0 test /Users/dimitry/Desktop/github/react-component-testing react-scripts test --env=jsdom

module.js:515 throw err; ^

Error: Cannot find module '/Users/dimitry/Desktop/github/react-component-testing/node_modules/jest -cli'

Thanks for any help and useful advice!

/EDIT/ Removing pacakage-lock.json, yarn.lock and node-modules and reinstalling all packages solves the issue, but I am not sure if this workaround is appropriate one in this case.

Aucun commentaire:

Enregistrer un commentaire