setupTests.js does not work in src/ path
See original GitHub issueI’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.
- setupTests.js
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.
Environment
node -v
: v8.9.4npm -v
: 5.8.0yarn --version
(if you use Yarn): 1.5.1npm ls react-scripts
(if you haven’t ejected): No- Operating system: Windows 10
This 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top GitHub Comments
setupTests.js
should be placed insrc
folder. I don’t see it in your examplein docs:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#filename-conventions