question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate complete jest config for angular libraries

See original GitHub issue

Expected Behavior

When generating a new angular library, a complete jest.config.js file should be generated, including everything needed for jest-preset-angular.

This would allow using the jest CLI directly which has a few benefits:

  • easier integration of vscode-jest
  • ability to run a single unit test file without specifying the library first
  • ability to run all unit tests in one go

Current Behavior

The jest.config.js does not include all necessary config properties required to run the tests. Instead, those are patched by the nx jest builder, preventing configuration by the user.

Steps to Reproduce

  1. Create nx workspace
  2. Generate a new angular library
  3. Try to run unit tests using the Jest CLI (cd <path_to_library_root> && jest)
  4. See failing tests

Solution

I would solve this by renaming skipSerializers to something like useAngularPreset, controlling all required properties for jest-preset-angular.

I’m happy to do a PR for this if that’s the way to go.

Related

#2768 #2377 #2314 #1506 #1091

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
FERNmancommented, Aug 17, 2021

For us it’s been resolved with the new jest.preset.js - thanks @Nx-team! 😄

2reactions
FERNmancommented, Apr 27, 2020

@wrslatz @jeserkin I just wanted to add the solution we are using to run tests using VSCode-Jest. This issue is somewhat of a requirement for it though (at least without touching generated libs), as all libs must have a working jest config.

I’ve uploaded the script on gist: https://gist.github.com/FERNman/14e3fe4086d6040cbb1f8e6174c9f0c6

What it does is pretty much a simplified version of nx affected:test combined with the Jest CLI. For some jest parameters (mainly arrays), the method parseJestArgs must probably be adapted.

Also, it may require maintenance from time to time if the nx workspace interface changes, but that should not happen too often.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate your Angular library to Jest | by Kevin Kreuzer - Medium
To configure Jest in a multi-projects file setup, we will create different Jest configurations. A base configuration in our root directory; A ...
Read more >
Using jest to test an Angular Library? - Stack Overflow
Trying to test an Angular 9 library with Jest, and I've installed the dependencies for Jest and Typescript within the local library ......
Read more >
Integrate Jest into an Angular application and library
The first thing to do is to create an application. ... The jest-preset-angular library will configure Jest and it will also configure the ......
Read more >
From Jasmine to Jest and Testing library in Angular Projects
In your project root, create the setup-jest.ts file and import the angular preset. Copy. import 'jest ...
Read more >
Angular Testing Series: How to add Jest to Angular project ...
Let's create jest.config.js file in your project's directory ... In first (1) line, we import the appropriate 'jest-preset-angular' library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found