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!
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
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?