jestjsangular-clits-jestjest-preset-angular

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

  • 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.