diff --git a/packages/angular/build/src/builders/unit-test/builder.ts b/packages/angular/build/src/builders/unit-test/builder.ts index fcf1f837a658..7b5410702aa8 100644 --- a/packages/angular/build/src/builders/unit-test/builder.ts +++ b/packages/angular/build/src/builders/unit-test/builder.ts @@ -115,8 +115,14 @@ export async function* execute( loadContent: async () => { const contents: string[] = [ // Initialize the Angular testing environment - `import { getTestBed } from '@angular/core/testing';`, + `import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';`, `import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';`, + `import { beforeEach, afterEach } from 'vitest';`, + '', + // Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/src/test_hooks.ts#L21-L29 + `beforeEach(getCleanupHook(false));`, + `afterEach(getCleanupHook(true));`, + '', `getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {`, ` errorOnUnknownElements: true,`, ` errorOnUnknownProperties: true,`,