I used Create React App to make a new project, and now i try to implement each feature i will need.
I am facing an issue i dont understand while trying to configure jest with reactjs. One my node_modules, react-dotenv
break jest test.
If i try to copy/past the issue line import env from 'react-dotenv';
directly in the root tested file Login.tsx
there is no error. I tried to configure moduleNameMapper
and search around without success..
I dont understand the problem, what am i missing?
Ok, i was missing mocks
and transformIgnorePatterns
Didn't really make transformIgnorePatterns
working using:
transformIgnorePatterns: ["node_modules/(?!react-dotenv)"],
but the mocks
moduleNameMapper: {
'^.+\\.(css|scss)$': '<rootDir>/__mocks__/CSSStub.config.js',
'react-dotenv': '<rootDir>/__mocks__/react-dotenv.tsx'
},
did the job.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.