I'm working with some simple tests. My project was made with Create React App. I have everything in a separeted folder src/tests. Everything was working fine but with just one file. When I wanted to add a new test file, I wanted to have in a single file the adapter configuration to not boilerplate the code. I added a setupTests.js to the src path and I ran the test again, but this time didn't work, throwing me the Enzyme message about the adapter. The configuration is the next and it works fine if I add it to each file.
I installed everything using npm but later I had to use yarn to resolve some dependencies issues.
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
I've seen that some people added:
{
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/path/to/your/file.js",
}
}
but it didn't work for me and I think is not a good practice to ovewrite the setup file like this way.
node -v: v8.9.4npm -v: 5.8.0yarn --version (if you use Yarn): 1.5.1npm ls react-scripts (if you haven鈥檛 ejected): NoThis is the link of my tests: https://github.com/DracotMolver/React-Practicing/tree/master/DragAndDrop/src/tests
By now I have the Enzyme adapter configuration on each file.
Any help I'll be thankful.
setupTests.js should be placed in src folder. I don't see it in your example
I know that must be placed there and i did. But here as i said above "... By now I have the Enzyme adapter configuration on each file". I pushed it like that because it works like this, i can pushed it in the way that doesn't work for me.
Today I had to change my OS and I couldn't replicate the issue. but now It's working. Thanks a lot @YevheniiKravchenko and @tabrindle for your time guys :+1:
I had this issue as well. And this was my fix!
Adding this to your package.json won't work if you have a jest.config.js file:
{
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/path/to/your/file.js",
}
}
Instead you have to add this code to your jest.config.js file like so:
module.exports = {
setupTestFrameworkScriptFile: "<rootDir>/src/setupTests.js"
}
Most helpful comment
setupTests.jsshould be placed insrcfolder. I don't see it in your example