Can't find libraries when running Jest tests
See original GitHub issueCurrent Behavior
After updating to the latest via migrate I am unable to run Jest unit tests as it doesn’t seem to be able to resolve my nx libraries. Similar to this issue: https://stackoverflow.com/questions/72606965/testing-with-nx-jest-and-angular-cant-find-library-when-running-tests
Expected Behavior
Should be able to run Jest tests when using nx libraries.
Failure Logs
Cannot find module ‘@org/shared:ui’ from ‘src/header/header.tsx’
Environment
"next": "^12.1.5",
"@nrwl/cypress": "14.3.1",
"@nrwl/eslint-plugin-nx": "14.3.1",
"@nrwl/jest": "14.3.1",
"@nrwl/js": "14.3.1",
"@nrwl/linter": "14.3.1",
"@nrwl/next": "14.3.1",
"@nrwl/node": "14.3.1",
"@nrwl/react": "14.3.1",
"@nrwl/storybook": "14.3.1",
"@nrwl/tao": "14.3.1",
"@nrwl/web": "14.3.1",
"@nrwl/workspace": "14.3.1",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:24 (3 by maintainers)
Top Results From Across the Web
Testing with Nx, Jest and Angular - Can't find library when ...
The import { EnvironmentService } from '@myorg/client-core'; is inside the paitent.guard.ts file. It can find the libraries when I run ng serve ...
Read more >Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why.
Read more >Configuring Jest
By default, Jest runs all tests and produces all errors into the console upon ... See the coverageProvider option for more details.
Read more >Testing React Apps - Jest
Run. npm; Yarn. npm install --save-dev react-test-renderer ... This way you won't see the props passed to the mock component in the snapshot ......
Read more >Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Experiencing the same issue after updating.
I resolved it by adding a moduleNameMapper fixed at the
cwd
jest.preset.js
It seems like moduleNameMapper should be a part of the
@nrwl/jest/preset
in the first place. When troubleshooting it seems like imports are being done relative to each libs folder pathI modified the preset from @KamalAman a little bit as the config crashing when there is JSON file in the project, and this config works for my nodejs test