enzyme-adapter-react-17 icon indicating copy to clipboard operation
enzyme-adapter-react-17 copied to clipboard

TypeError: Adapter is not a constructor

Open rkichenama opened this issue 2 years ago • 2 comments

I keep getting errors following the documentation for setting up Enzyme with the default export, like in #21.

setupEnzyme.ts

import { configure } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';

configure({ adapter: new Adapter() });

with packages:

"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",

and the error jest output:

> jest -c jest.config.js --coverage

 FAIL  src/lib/group.test.ts
  ● Test suite failed to run

    TypeError: enzyme_adapter_react_17_1.default is not a constructor

      4 | import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
      5 |
    > 6 | configure({ adapter: new Adapter() });
        |                      ^

      at Object.<anonymous> (setupEnzyme.ts:6:22)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:401:19)

I need to import like below to start jest runs.

import { configure } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17/build/ReactSeventeenAdapter';

configure({ adapter: Adapter });

rkichenama avatar Nov 15 '21 21:11 rkichenama

Here's how I solved it:

in tsconfig.json : "esModuleInterop": true

lilong7676 avatar Dec 22 '21 06:12 lilong7676

You can also change the import to:

import * as Adapter from '@wojtekmaj/enzyme-adapter-react-17';

taranek avatar Mar 10 '22 13:03 taranek