Skip to content

Commit 7b6abea

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 7b6abea

File tree

1 file changed

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

1 file changed

+7
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ 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+
// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/src/test_hooks.ts#L21-L29
123+
`beforeEach(getCleanupHook(false));`,
124+
`afterEach(getCleanupHook(true));`,
125+
'',
120126
`getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {`,
121127
` errorOnUnknownElements: true,`,
122128
` errorOnUnknownProperties: true,`,

0 commit comments

Comments
 (0)