• Register
0 votes

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

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:


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 2.1K views
Problem : I am trying to start the Redux application I just cloned from the GitHub repository. I tried to run it with the below command npm start But I am getting below error > react-redux@1.0.0 start /home/workspace/assignment > webpack-dev-server --config ./ ... output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install? How can I fix the above error?
asked Jan 20 jwilliam 3.9k points
0 votes
1 answer 101 views
Problem: I have recently started learning about React, Babel, JSX and JS. Now I am receiving an error from a babel if I tried to compile my JSX code into a JS code. Please find the error: &ldquo;Jsx value should be either an expression or a quoted jsx text.&rdquo ... out in my searching on interenet that prop values should be passed only between {}, but adding these to my code did not help me.
asked Aug 13 Raphael Pacheco 4.9k points
0 votes
2 answers 582 views
Problem : Facing below error: Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions. I wanted to add comments with all posts. So when fetch posts are run I want to call fetch comment API for every post. export function ... API.fetchComments(postAllId).then(comments => {     return {       type: BIND_COMMENTS,       comments,       posAlltId     }  }) }
asked Jan 17 jwilliam 3.9k points
0 votes
2 answers 108 views
Problem : I am trying to learn React JS. I have written a code for component . I also have the data that I get from a Data Base, and whose current state (myDB) I dispatch.I am trying to use data from myDB object and then want to display some of the ... a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons How to fix this issue ?
asked Feb 22 mphil 2.3k points
0 votes
1 answer 1.1K views
Problem : I have a carousel file in which I want to get my index.js and build the block.build.js, and my webpack.config.js But I face below error message: ERROR in ./index.js Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. Does anyone know the solution on this?
asked Jan 18 jwilliam 3.9k points