mercredi 4 mars 2020

How to configure Jest in PhpStorm for React application (create-react-app flavor)

I'm trying to run tests from within PhpStorm IDE. But IDE throws an error and doesn't accept my configuration as valid. Although I configured it as official PhpStorm documentation explains it.

I have standard CRA application. I want to use Enzyme and Jest as test utils.

I use jest-enzyme and jest-environment-enzyme packages along with enzyme and enzyme-adapter-react-16.

PhpStorm docs says:

Specify the location of the jest, react-scripts, react-script-ts, react-super-scripts, or react-awesome-scripts package.

I've tried to specify both, jest or react-scripts. And both options do not work in PhpStorm.

Here are my two configurations:

No.1: Jest

IDE throws SyntaxError because it doesn't recognize React components. I think it doesn't know how to use Babel or Webpack. But IDE documentation doesn't mention anything about how to point IDE to Babel or other compilers.

enter image description here

No.2: react-scripts

IDE throws argv.config.match is not a function. It can't even start testing.

enter image description here

My jest.config.js is as follows as it requited by jest-environment-enzyme:

module.exports = {
  "setupFilesAfterEnv": ["jest-enzyme"],
  "testEnvironment": "enzyme",
  "verbose": true,
};

Aucun commentaire:

Enregistrer un commentaire