How do I specify unit paths for Jest tests?

It doesn't seem to respect the NODE_PATHS env variable and instead just searches the current directory.

+3


source to share


2 answers


Jest does not currently support NODE_PATH

module permissions in its code (for no reason other than that it just wasn't built).



We are currently tracking this issue: https://github.com/facebook/jest/issues/102

+1


source


Jest doesn't read NODE_PATH. In our project where we are using webpack, we ran into problems with alias

and moduleDirectories

. Jest did not resolve the path correctly. Therefore, we decided that like this: Suppose you want to import

import SomeComp from 'components/SomeComp';

      

which is located in /src/components/SomeComp/index.js



In package.json

define:

"jest": {
  "moduleNameMapper": {
    "/src/(.*)": "<rootDir>/src/$1"
  }
},

      

0


source







All Articles