'Jest Error: Cannot set base providers. After Angular v13 upgrade using 'ng test'

After upgrading Angular to v 13 when I try to run my tests in the jest environment I have an error:

Cannot set base providers because it has already been called
import 'jest-preset-angular/setup-jest';

Additionally, I configured Jest like it pointed out in this post: https://thymikee.github.io/jest-preset-angular/docs/next/guides/esm-support/ but it does not help me. Need help. How can I fix my tests?



Solution 1:[1]

I've come across the same issue. It seems that ESM support with Angular 13 is not released yet. https://thymikee.github.io/jest-preset-angular/docs/next/guides/angular-13+

However, there's a PR already merged (https://github.com/thymikee/jest-preset-angular/pull/1122) that presumably should fix the issue.

Solution 2:[2]

My solution was to remove the setup-jest.ts file, since import 'jest-preset-angular/setup-jest'; is already executed by @angular-builders/jest.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Juan
Solution 2 RGe