Skip to content

Commit

Permalink
fix: address comments, run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
u120655 committed May 17, 2022
1 parent 99e4979 commit 8462a56
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
2 changes: 2 additions & 0 deletions setup-jest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
68 changes: 36 additions & 32 deletions src/config/setup-jest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
3 changes: 2 additions & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 8462a56

Please sign in to comment.