Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

TypeError: Adapter is not a constructor #36

Closed
rkichenama opened this issue Nov 15, 2021 · 2 comments
Closed

TypeError: Adapter is not a constructor #36

rkichenama opened this issue Nov 15, 2021 · 2 comments
Labels
question Further information is requested

Comments

@rkichenama
Copy link

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 });
@wojtekmaj wojtekmaj added the question Further information is requested label Nov 23, 2021
@lilong7676
Copy link

Here's how I solved it:

in tsconfig.json :
"esModuleInterop": true

@taranek
Copy link

taranek commented Mar 10, 2022

You can also change the import to:

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants