From 3a4031e495712efe3b9c6b326becd42fb6673d3d Mon Sep 17 00:00:00 2001 From: Chabbey Date: Mon, 25 Nov 2024 10:13:17 +0100 Subject: [PATCH] chore(testing): remove depreciation warning jest-preset-angular is now using setupZoneTestEnv --- .../angular/src/generators/utils/add-jest.ts | 29 ++++++++++++------- .../configuration/configuration.spec.ts | 2 +- .../files-angular/src/test-setup.ts__tmpl__ | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/angular/src/generators/utils/add-jest.ts b/packages/angular/src/generators/utils/add-jest.ts index b9fe5e713083c7..67c12c570c36d6 100644 --- a/packages/angular/src/generators/utils/add-jest.ts +++ b/packages/angular/src/generators/utils/add-jest.ts @@ -49,18 +49,25 @@ export async function addJest( 'src', 'test-setup.ts' ); - if (options.strict && tree.exists(setupFile)) { + if (tree.exists(setupFile)) { const contents = tree.read(setupFile, 'utf-8'); - tree.write( - setupFile, - `// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment -globalThis.ngJest = { - testEnvironmentOptions: { + if (options.strict) { + tree.write( + setupFile, + `${contents} +setupZoneTestEnv( errorOnUnknownElements: true, - errorOnUnknownProperties: true, - }, -}; -${contents}` - ); + errorOnUnknownProperties: true +); +` + ); + } else { + tree.write( + setupFile, + `${contents} +setupZoneTestEnv(); +` + ); + } } } diff --git a/packages/jest/src/generators/configuration/configuration.spec.ts b/packages/jest/src/generators/configuration/configuration.spec.ts index 333a4d3c7a5872..2972e5d3a95084 100644 --- a/packages/jest/src/generators/configuration/configuration.spec.ts +++ b/packages/jest/src/generators/configuration/configuration.spec.ts @@ -55,7 +55,7 @@ describe('jestProject', () => { } as JestProjectSchema); expect(tree.read('libs/lib1/src/test-setup.ts', 'utf-8')) .toMatchInlineSnapshot(` - "import 'jest-preset-angular/setup-jest'; + "import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone'; " `); expect(tree.exists('libs/lib1/jest.config.ts')).toBeTruthy(); diff --git a/packages/jest/src/generators/configuration/files-angular/src/test-setup.ts__tmpl__ b/packages/jest/src/generators/configuration/files-angular/src/test-setup.ts__tmpl__ index 1100b3e8a6ed08..6e1a56a0597185 100644 --- a/packages/jest/src/generators/configuration/files-angular/src/test-setup.ts__tmpl__ +++ b/packages/jest/src/generators/configuration/files-angular/src/test-setup.ts__tmpl__ @@ -1 +1 @@ -import 'jest-preset-angular/setup-jest'; +import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';