Ad

Why Am I Getting The Following Error: Enzyme Internal Error: Configured Enzyme Adapter Did Not Inherit From The EnzymeAdapter Base Class

I have set up jest and enzyme and can't get it to run. It complains about the EnzymeAdapter base class.

I have tried

configure({}) with import { configure } from 'enzyme'

Enzyme.configure({}) with import Enzyme from 'enzyme'

new Adapter() with import Adapter from 'enzyme-adapter-react-16';

new EnzymeAdapter() with import EnzymeAdapter from 'enzyme-adapter-react-16';

My setupTests.js:

import Enzyme, { configure } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new EnzymeAdapter() });

The error i get for each test class is the following:

Enzyme Internal Error: configured enzyme adapter did not inherit from the EnzymeAdapter base class

      2 | import EnzymeAdapter from 'enzyme-adapter-react-16';
      3 | 
    > 4 | Enzyme.configure({ adapter: new EnzymeAdapter() });
        |        ^

      at validateAdapter (node_modules/enzyme/src/validateAdapter.js:43:11)
      at Object.merge [as configure] (node_modules/enzyme/src/configuration.js:11:5)
      at Object.configure (src/setupTests.js:4:8)
          at Array.forEach (<anonymous>)

Since I get it for every test suite the setupTests.js works.

The same error appears if I do the configure in the test.js itself

I've been searching for hours with no luck. Has anybody encountered the issue before or have a solution?

Thanks in advance!

Ad

Answer

Found the error!

There was an issue with jest. I had to delete node_modules and package-lock.json/yarn.lock, and remove jest from devDependencies in package.json. Why? Because react-scripts installed a different version of jest than what was written in package.json.

Then I installed all dependencies again with yarn in the terminal (npm can be buggy when it comes to dependencies and versioning) and did yarn test in the project-folder.

EDIT #1 Thanks to Mitch Lillie for helping me on the way to find the solution

Ad
source: stackoverflow.com
Ad