I have a problem. When I run Jest tests it can't resolve my imports with at (@
) signs. I have an error:
FAIL src/App.test.js
● Test suite failed to run
Cannot find module '@/helpers/configureStore' from 'App.js'
How do I resolve this error?
I found the solution in this post. So according to the jest docs we should go to our package.json
file, and make sure our config contains something like:
{
"jest": {
"moduleNameMapper": {
"@/(.*)$": "<rootDir>/src/$1"
}
}
}
"@/(.*)$": "<rootDir>/src/$1"
that's a cool regex which will resolve our @/helpers/configureStore
to src/helpers/configureStore
.
Also remember to quit from jest interactive mode (with q
key) and run it again to see changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With