Create-react-app: Adding enzyme to React 16+ requires you to eject because you can't configure Jest further

Created on 12 Oct 2017  路  2Comments  路  Source: facebook/create-react-app

Is this a bug report?

Nope

Which terms did you search for in User Guide?

Enzyme

Environment

  1. node -v: 8.4.0
  2. npm -v:
  3. yarn --version (if you use Yarn): 1.2.0
  4. npm ls react-scripts (if you haven鈥檛 ejected): 1.0.14

Then, specify:

  1. Operating system: OS X
  2. Browser and version (if relevant):

Expected Behavior

You can get a basic Enzyme setup without having to eject.

Actual Behavior

Adding enzyme to React 16+ requires you to eject because you can't configure Jest further to get enzyme's adapters setup.

Most helpful comment

you can't configure Jest further to get enzyme's adapters setup.

This is not correct. CRA has always supported running some code before every test:

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#initializing-test-environment

Here is an example of working setup:

https://github.com/facebookincubator/create-react-app/issues/3199#issuecomment-334801311

Somebody should send a PR to Enzyme to document usage with CRA, and update our docs as well.

All 2 comments

you can't configure Jest further to get enzyme's adapters setup.

This is not correct. CRA has always supported running some code before every test:

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#initializing-test-environment

Here is an example of working setup:

https://github.com/facebookincubator/create-react-app/issues/3199#issuecomment-334801311

Somebody should send a PR to Enzyme to document usage with CRA, and update our docs as well.

Was this page helpful?
0 / 5 - 0 ratings