• Register
0 votes
493 views

Problem :

I have created the new React application by just using create-react-app and I amtrying to write a unit test to the component named "MessageBox" that I have created in the application.

I have also added the file under my 'src' folder named 'setupTests.js' with the below content:

import * as msenzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';
msenzyme.configure({ adapter: new Adapter() });

I ran it by below command :

npm test

But I got the below error:

Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To configure an adapter, you should call msenzyme.configure({ > adapter: new Adapter() })

Does someone know how can I solve this problem?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Many of people will tell you to import setupTests.js into your test file. Or to configure enzyme adapter in each of the test file. This will solve your immediate problem only.

But for the long term, if you add the jest.config.js file to your project root. Then you can configure it to run the setup file on launch as shown below:

jest.config.js

module.exports = {
setupTestFrameworkScriptFile: "<rootDir>/src/setupTests.ts"
}

This will tell the Jest to run setupTest.ts every time it is launched.

This way if you need to add the polyfills and add global mock like the localstorage then you can add them to your setupTests file and it will be configured everywhere.

9 7 4
38,600 points

Related questions

0 votes
1 answer 3 views
3 views
Problem: I created a new React application by create-react-app and I wanted to write a unit test to a component named "MessageBox" that I created in the application. This is the unit test that I wrote: import MessageBox from "../MessageBox"; import { shallow } from ... To configure an adapter, you should call Enzyme.configure({ > adapter: new Adapter() }) Do you know what can solve this problem?
asked Apr 26 anika11 32.2k points
0 votes
1 answer 13 views
13 views
Problem: I am trying to set inline styles in my React application. In this case, for a span: <span className="myClass" style={{float : 'left', paddingRight : '5px'}} > </span> React tells me: Uncaught Invariant Violation: The style prop expects a mapping from style ... so I did paddingRight: 5 as well as paddingRight: 5 + 'px' as well as paddingRight : 5px, but I didn't have any success!
asked Apr 26 Moumita Bhowmick 12.9k points
0 votes
1 answer 4 views
4 views
Problem: Can anyone facilitate with this >'yarn' is not recognized as an internal or external command,
asked 4 days ago Sawyer Parviz 13.2k points
0 votes
1 answer 71 views
71 views
Problem: yarn' is not recognized as an internal or external command, operable program or batch file.
asked Feb 18 Lucky Guy 1.5k points
0 votes
1 answer 96 views
96 views
Problem: yarn' is not recognized as an internal or external command.
asked Feb 16 Ethan ross 2.7k points
0 votes
1 answer 4 views
4 views
Problem: I'm trying to host a website on github and it keeps showing this error : "Unavailable for your site because your domain is not properly configured to support HTTPS(coursera-confusion.com) &mdash; Troubleshooting custom domains HTTPS provides a layer of encryption that ... will only be served over HTTPS. Learn more. " This is my first time hosting a web repo on github.please help.
asked Apr 25 sumaiya simi 43.9k points
1 vote
1 answer 103 views
103 views
Problem: I am working on React project where I am trying to wrap text around an image and I understand that this style="float: left" is html 5. However if I use the following code: <div className="container"> <img src={myImageSource} alt="swimmer" height="300" width="300" align="left" /> <p> This is where the other text goes about the swimmer</p> </div> It works! Why can't I use style in React?
asked Mar 22 Sabbir Hossain 14.6k points
0 votes
1 answer 47 views
47 views
Problem syntax error: adjacent jsx elements must be wrapped in an enclosing tag.
asked Feb 11 charles mathews 5.5k points
0 votes
1 answer 7 views
7 views
Problem: Does anyone have the skills to resolve this error? >Media error: format(s) not supported or source(s) not found.
asked 3 days ago Ashok Dileep 5.3k points
0 votes
1 answer 4 views
4 views
Problem: Where ought to I seek an answer? >Module not found: error: can't resolve 'core-js/es7/reflect'.
asked 4 days ago Ashok Dileep 5.3k points