Skip to content

Commit 8e0b14f

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: angular#30186
1 parent 8129483 commit 8e0b14f

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
@@ -124,8 +124,14 @@ export async function* execute(
124124
loadContent: async () => {
125125
const contents: string[] = [
126126
// Initialize the Angular testing environment
127-
`import { getTestBed } from '@angular/core/testing';`,
127+
`import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';`,
128128
`import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';`,
129+
`import { beforeEach, afterEach } from 'vitest';`,
130+
'',
131+
// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/src/test_hooks.ts#L21-L29
132+
`beforeEach(getCleanupHook(false));`,
133+
`afterEach(getCleanupHook(true));`,
134+
'',
129135
`getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {`,
130136
` errorOnUnknownElements: true,`,
131137
` errorOnUnknownProperties: true,`,

0 commit comments

Comments
 (0)