Skip to content

Commit 40ce720

Browse files
committed
fix(@angular/build): perform testing module cleanup when using Vitest
Ensure proper cleanup of the Angular testing module when running tests with Vitest. Closes: #30186
1 parent 05485ed commit 40ce720

File tree

1 file changed

+6
-1
lines changed
  • packages/angular/build/src/builders/unit-test

1 file changed

+6
-1
lines changed

packages/angular/build/src/builders/unit-test/builder.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ export async function* execute(
115115
loadContent: async () => {
116116
const contents: string[] = [
117117
// Initialize the Angular testing environment
118-
`import { getTestBed } from '@angular/core/testing';`,
118+
`import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';`,
119119
`import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';`,
120+
`import { beforeEach, afterEach } from 'vitest';`,
121+
'',
122+
`beforeEach(getCleanupHook(false))`,
123+
`afterEach(getCleanupHook(true))`,
124+
'',
120125
`getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {`,
121126
` errorOnUnknownElements: true,`,
122127
` errorOnUnknownProperties: true,`,

0 commit comments

Comments
 (0)