admin管理员组

文章数量:1402953

I changed my angular app V 19.x to ZoneLess app (I did uninstall the Zone.js and removed its import from polyfills.ts). All works fine. The issue is when running the unit test (using jest). The spec files have been all changed to use Zoneless adding:

provideExperimentalZonelessChangeDetection() in providers:[] matadata etc.

The test runs all fine and no errors, but I keep getting the following warning in the console for each spec file which is bad:

console.warn
  NG0914: The application is using zoneless change detection, but is still loading Zone.js. Consider removing Zone.js to get the full benefits of zoneless. In applications using the Angular CLI, Zone.js is typically included in the "polyfills" section of the angular.json file.

  247 |     providers: [
> 248 |         provideExperimentalZonelessChangeDetection(),
      |                                                   ^
  249 |         {
  250 |             provide: AppSettingsService,
  251 |             useValue: getAppSettingsServiceSpy()
                },
                ...
           ]

I have been searching and tried some options, but none of my tries fixes the warning. Any idea or a hint what could be the cause please?

I changed my angular app V 19.x to ZoneLess app (I did uninstall the Zone.js and removed its import from polyfills.ts). All works fine. The issue is when running the unit test (using jest). The spec files have been all changed to use Zoneless adding:

provideExperimentalZonelessChangeDetection() in providers:[] matadata etc.

The test runs all fine and no errors, but I keep getting the following warning in the console for each spec file which is bad:

console.warn
  NG0914: The application is using zoneless change detection, but is still loading Zone.js. Consider removing Zone.js to get the full benefits of zoneless. In applications using the Angular CLI, Zone.js is typically included in the "polyfills" section of the angular.json file.

  247 |     providers: [
> 248 |         provideExperimentalZonelessChangeDetection(),
      |                                                   ^
  249 |         {
  250 |             provide: AppSettingsService,
  251 |             useValue: getAppSettingsServiceSpy()
                },
                ...
           ]

I have been searching and tried some options, but none of my tries fixes the warning. Any idea or a hint what could be the cause please?

Share Improve this question asked Mar 21 at 7:54 k.vincentk.vincent 4,1638 gold badges43 silver badges85 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
You need change your file setup-jest.ts for that:
import { setupZonelessTestEnv } from 'jest-preset-angular/setup-env/zoneless';

setupZonelessTestEnv();

You can find a documentation here

https://thymikee.github.io/jest-preset-angular/docs/getting-started/testbed-environment

本文标签: How to fix unit test warnings for angularzoneless applicationStack Overflow