• 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

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:


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 11 views
Problem syntax error: adjacent jsx elements must be wrapped in an enclosing tag.
asked Feb 11 charles mathews 3.8k points
0 votes
1 answer 9 views
Problem: yarn' is not recognized as an internal or external command, operable program or batch file.
asked 6 days ago Lucky Guy 1.4k points
0 votes
1 answer 13 views
Problem: yarn' is not recognized as an internal or external command.
asked Feb 16 Ethan ross 1.8k points
0 votes
1 answer 3.5K 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, 2020 jwilliam 3.9k points
0 votes
1 answer 460 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, 2020 Raphael Pacheco 4.9k points
0 votes
2 answers 1K 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, 2020 jwilliam 3.9k points
0 votes
2 answers 335 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, 2020 mphil 2.3k points
0 votes
1 answer 2K 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, 2020 jwilliam 3.9k points
0 votes
1 answer 374 views
Problem : I have the React project using the Webpack and Babel. When I created it on the office computer, my Webpack ran fine. But when I cloned my project onto the personal computer, it gave me below error : ERROR in ./ ... native) at OptionManager.resolvePresets (/Users/alecxe/Desktop/w6d5/minesweeper/node_modules/babel-core/lib/transformation/file/options/option-manager.js:269:20)
asked Jan 7, 2020 alecxe 7.5k points
0 votes
1 answer 42 views
Here is a code example showing how to use hooks: import { useState } from 'react'; function Example() { // Declare a new state variable, which we'll call "count" const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> <button onClick={( ... the following installed packages "react": "^16.7.0-alpha.2", "react-dom": "^16.7.0-alpha.2" Any explanations and fixes to this?
asked Jan 23 khaled 280 points