Skip to content

Commit 55e3543

Browse files
committed
feat(@angular/build): disable TestBed teardown during debugging in Vitest
When running unit tests in debug mode, it is beneficial to keep the component's DOM state intact after the test completes for inspection. This change disables the automatic TestBed teardown (destroyAfterEach) when the 'debug' option is enabled.
1 parent 164e7db commit 55e3543

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { RunnerOptions } from '../api';
1717
function createTestBedInitVirtualFile(
1818
providersFile: string | undefined,
1919
projectSourceRoot: string,
20+
teardown: boolean,
2021
polyfills: string[] = [],
2122
): string {
2223
const usesZoneJS = polyfills.includes('zone.js');
@@ -58,6 +59,7 @@ function createTestBedInitVirtualFile(
5859
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {
5960
errorOnUnknownElements: true,
6061
errorOnUnknownProperties: true,
62+
${teardown === false ? 'teardown: { destroyAfterEach: false },' : ''}
6163
});
6264
}
6365
`;
@@ -133,6 +135,7 @@ export async function getVitestBuildOptions(
133135
const testBedInitContents = createTestBedInitVirtualFile(
134136
providersFile,
135137
projectSourceRoot,
138+
!options.debug,
136139
buildOptions.polyfills,
137140
);
138141

0 commit comments

Comments
 (0)