-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NX Workspace with Jest implementation #497
Comments
First install jest-preset-angular: create a tsconfig.spec.json in root with content:
add jest.config.json at same level with:
add jestGlobalMocks.ts with:
if you want to use whatwg-fetch and jest-localstorage-mock you should install them too (if not, just remove them from the previous scripts and leave jestGlobalMocks empty). add setupJest.ts with:
modify package.json scripts with:
|
Thank you for the answer @sixtoad ! |
@jschwarty , just discovered that there is a problem with HTML, the global config overwrite fully jest-preset-angular, so you need to add "TRANSFORM_HTML": true in:
so it will be:
in jest.config.json |
Great answer, many thanks, but has anyone got any guidance to share on getting it to work with nx 6? It can't find my projects in libs folder. It works well from Karma, but on any spec that imports from a lib folder I get the following: Cannot find module '@mylibs/mylib' from 'somespec.ts' |
Depending on how you import the files from your lib you maybe have to setup the module name mapping in jest configuration. Since jest does not understand the path mappings in the tsconfig this is the way to do it. https://github.com/thymikee/jest-preset-angular#absolute-imports |
@darronj Could you share how you set this up with nrwl 6? |
Unfortunately I never got it to work. I still have the branch ready if anyone has any good ideas though. |
@jschwarty I think this issue should be reopened. Additionally with |
You might be able to use affected:apps to generate a filter for jest but that feels... hacky. |
@darronj I've actually figured it out. I'll make a post on Medium about it soon since I too couldn't find any info on this (this week, I promise). It wasn't too difficult. :) |
@Nxt3 - we should add an Nx Schematic to support the |
@ThomasBurleson I couldn't agree more. When I get around to writing the (brief) article, I'll open a feature request for it. 👍 I gotta make sure I remember everything I did lol |
Issue #623 has the necessary info. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
How can you configure Jest with NX Workspace and remove jasmine and karma configs
The text was updated successfully, but these errors were encountered: