Currently I am using automatic imports in my Next.js project, configured by jsconfig.json in the root directory:
{
"typeAcquisition": {
"include": ["jest"]
},
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["components/*"],
"@/functions/*": ["functions/*"],
"@/styles/*": ["styles/*"],
"@/pages/*": ["pages/*"]
}
},
"exclude": ["node_modules"]
}
When I add jest testing in a test directory at the root, the tests are not pointing towards the root directory. I have tried:
- adding a
jest.config.jsfile that points to the root directory - appending
typeAcquisitionto thejsconfig.js - adding a
jsconfig.jsto thetestsdirectory.
I am not sure which is the right path, or how to properly set this up, but none of these seem to work for me. I can get the tests to run by removing the imports altogether and instead just ../../-ing my way through the directory, but this requires me to change all the nested files as well
- i.e.: In pages/api/budget, I call a handler to go to functions/api/fetchBudget. In order for the Jest testing to reach it, I have to change the import statements on both of these to use the standard ../../ syntax, instead of @pages/.. or @functions that I have set up.
TL;DR: How do I set up Jest testing to go through my project's root directory jsconfig.json; or, in lieu of that, how can I set up Jest testing with it's own jsconfig.json?