question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on tests when Enzyme is added

See original GitHub issue

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes;

Which terms did you search for in User Guide?

I searched about testing, about enzyme and on the troubleshooting page as well.

Environment

  1. node -v: v6.11.3
  2. npm -v: 4.6.1
  3. yarn --version (if you use Yarn): 1.1.0
  4. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.14

Then, specify:

  1. Operating system: Windows

Steps to Reproduce

  1. npm install -g create-react-app
  2. create-react-app test-jest-enzyme
  3. cd test-jest-enzyme
  4. Change file src/App.test.js to be:
import React from 'react';
import App from './App';
import {shallow} from "enzyme";

it('renders without crashing', () => {
    shallow(<App />);
});
  1. npm test

Expected Behavior

The tests would pass and no exception would be thrown.

Actual Behavior

Will give:

          Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To
          configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
          before using any of Enzyme's top level APIs, where `Adapter` is the adapter
          corresponding to the library currently being tested. For example:

          import Adapter from 'enzyme-adapter-react-15';

          To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html


      at validateAdapter (node_modules/enzyme/build/validateAdapter.js:14:11)
      at Object.<anonymous>.it (src/App.test.js:6:25)

Reproducible Demo

https://gitlab.com/DevLearn/jest-react-broken

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

20reactions
pedro-stanakacommented, Oct 2, 2017

I can confirm that putting:

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';

configure({ adapter: new Adapter() });

In the src/setupTests.js file solves the issue.

14reactions
goozocommented, Oct 13, 2017

ok, think I fixed it, not sure if it’s the correct way but it works for ejected CRA by adding to package.json jest property :

"jest": {
    ...
    "setupFiles": [
      "<rootDir>/src/setupTests.js"
    ],
    ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest & Enzyme test error with React Context API - Stack Overflow
I am testing a React app with Jest & Enzyme. When I run npm run test I get the error in UserContext.jsx that...
Read more >
Improve your test assertions and error messages with jest ...
To improve these error messages and to introduce some new good-looking assertions, we'll add the assertion library jest-enzyme to our project.
Read more >
Errors in measuring enzyme activity by reaction-rate methods
Reaction-rate and two-point enzyme assays have sources of error inherent in their methodologies. There are also major errors due to the analytical system ......
Read more >
Troubleshooting Common Issues with Restriction Digestion ...
In this article, we have highlighted the most common issues while performing digestion reactions and probable causes to help you resolve your hurdles....
Read more >
Enzyme Linked Immunosorbent Assay - StatPearls - NCBI - NIH
ELISA testing is used to diagnose HIV infection, pregnancy tests, and blood ... Then the secondary enzyme-conjugated antibody is added and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found