wojtekmaj / enzyme-adapter-react-17

Unofficial adapter for React 17 for Enzyme.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Adapter is not a constructor

rkichenama opened this issue · 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 });

Here's how I solved it:

in tsconfig.json :
"esModuleInterop": true

You can also change the import to:

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