From 8462a5690c322e428008a8a34f42b3a819ddcd01 Mon Sep 17 00:00:00 2001 From: u120655 Date: Tue, 17 May 2022 09:29:51 +0200 Subject: [PATCH] fix: address comments, run prettier --- setup-jest.mjs | 2 ++ src/config/setup-jest.spec.ts | 68 ++++++++++++++++++----------------- src/global.d.ts | 3 +- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/setup-jest.mjs b/setup-jest.mjs index 4dbea61fcd..d20b3107f6 100644 --- a/setup-jest.mjs +++ b/setup-jest.mjs @@ -6,6 +6,8 @@ let teardown = globalThis.ngJest?.teardown; const configuredDestroyAfterEach = globalThis.ngJest?.destroyAfterEach; if (configuredDestroyAfterEach) { + console.warn(`Passing destroyAfterEach for configuring the test environment has been deprecated`); + console.warn('Please pass a ModuleTeardownOptions') teardown = { destroyAfterEach: true, }; diff --git a/src/config/setup-jest.spec.ts b/src/config/setup-jest.spec.ts index a5c5a79623..17505e22c5 100644 --- a/src/config/setup-jest.spec.ts +++ b/src/config/setup-jest.spec.ts @@ -51,46 +51,50 @@ describe('setup-jest', () => { jest.resetModules(); }); - test('should initialize test environment with getTestBed() and initTestEnvironment() for CJS setup-jest', async () => { - globalThis.ngJest = { - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, - }; - await import('../../setup-jest'); + describe('for CSJ setup-jest, test environment initialization', () => { + test('should call getTestBed() and initTestEnvironment() with the ModuleTeardownOptions object passed to ngJest', async () => { + globalThis.ngJest = { + teardown: { + destroyAfterEach: false, + rethrowErrors: true, + }, + }; + await import('../../setup-jest'); - expect(mockUmdZoneJs).toHaveBeenCalled(); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, + expect(mockUmdZoneJs).toHaveBeenCalled(); + assertOnInitTestEnv(); + expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ + teardown: { + destroyAfterEach: false, + rethrowErrors: true, + }, + }); }); - }); - test('should initialize test environment with getTestBed() and initTestEnvironment() for CJS setup-jest / 2', async () => { - globalThis.ngJest = { - destroyAfterEach: true, - }; + test('should call getTestBed() and initTestEnvironment() with the destroyAfterEach passed to ngJest', async () => { + globalThis.ngJest = { + destroyAfterEach: true, + }; - await import('../../setup-jest'); + await import('../../setup-jest'); - expect(mockUmdZoneJs).toHaveBeenCalled(); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: true, - }, + expect(mockUmdZoneJs).toHaveBeenCalled(); + assertOnInitTestEnv(); + expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ + teardown: { + destroyAfterEach: true, + }, + }); }); }); - test('should initialize test environment with getTestBed() and initTestEnvironment() for ESM setup-jest', async () => { - await import('../../setup-jest.mjs'); + describe('for ESM setup-jest, test environment initialization', () => { + test('should call getTestBed() and initTestEnvironment()', async () => { + await import('../../setup-jest.mjs'); - expect(mockEsmZoneJs).toHaveBeenCalled(); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toBeUndefined(); + expect(mockEsmZoneJs).toHaveBeenCalled(); + assertOnInitTestEnv(); + expect(mockInitTestEnvironment.mock.calls[0][2]).toBeUndefined(); + }); }); }); diff --git a/src/global.d.ts b/src/global.d.ts index b43f3bc467..f6bbfe11f1 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,11 +1,12 @@ /* eslint-disable */ -import {ModuleTeardownOptions} from "@angular/core/testing"; +import type { ModuleTeardownOptions } from "@angular/core/testing"; declare global { var ngJest: { skipNgcc?: boolean; tsconfig?: string; + destroyAfterEach?: boolean; teardown?: ModuleTeardownOptions; } | undefined; }