cfaester / enzyme-adapter-react-18

MIT License
38 stars 12 forks source link

How to initialise it in CJS? #8

Closed ashleyyy94 closed 5 months ago

ashleyyy94 commented 11 months ago

I am trying to configure the Enzyme adapter using the below in my jest.setup.js:

const { configure } = require('enzyme'); const { Adapter } = require('@cfaester/enzyme-adapter-react-18'); configure({ adapter: new Adapter() });

However, when I run my test files, it is throwing a typerror as below: image

Any advice?

Thank you.

hjelmeir commented 9 months ago

did you try const Adapter = require('@cfaester/enzyme-adapter-react-18')?

nasimoyz commented 8 months ago

Looks like const Adapter = require('@cfaester/enzyme-adapter-react-18'); will give you: [console log] Adapter { default: [class ReactEighteenAdapter extends EnzymeAdapter] }

We can access the default property inside that object instead via: const Adapter = require('@cfaester/enzyme-adapter-react-18').default;

cfaester commented 5 months ago

Seems resolved.