How to fix unit test warnings for angular-zoneless application? - Stack Overflow

I changed my angular app V 19.x to ZoneLess app (I did uninstall the Zone.js and removed its import fro

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744367763a4570793.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信