I use Babel Jest to translate my code for testing purposes. I cannot figure out how to use the path relative to the root of the project.
For example, if in a test file I import a module using: /imports/ui/myModuleJest gives an error
Cannot find module
'/Users/me/dev/myProject/Users/me/dev/myProject/imports/ui/myModule' from 'test.jsx'`
But if I import a module with a relative path, for example: ../../ui/myModuleit works.
My .babelrc:
{
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"babel-root-slash-import"
],
"presets": [
"es2015",
"react",
"stage-0"
],
"env": {
"test": {
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"babel-root-slash-import"
],
"presets": [
"es2015",
"react",
"stage-0"
]
}
}
}
My Jest Configuration:
"jest": {
"roots": ["<rootDir>/imports/tests/jest"]
},
source
share