Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function createTestBedInitVirtualFile(
import { afterEach, beforeEach } from 'vitest';
${providersImport}

// The beforeEach and afterEach hooks are registered outside the globalThis guard.
// This ensures that the hooks are always applied, even in non-isolated browser environments.
// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/srcs/test_hooks.ts#L21-L29
beforeEach(getCleanupHook(false));
afterEach(getCleanupHook(true));

const ANGULAR_TESTBED_SETUP = Symbol.for('@angular/cli/testbed-setup');
if (!globalThis[ANGULAR_TESTBED_SETUP]) {
globalThis[ANGULAR_TESTBED_SETUP] = true;
Expand All @@ -44,10 +50,6 @@ function createTestBedInitVirtualFile(
// In a non-isolated environment, this setup file can be executed multiple times.
// The guard condition above ensures that the setup is only performed once.

// Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/srcs/test_hooks.ts#L21-L29
beforeEach(getCleanupHook(false));
afterEach(getCleanupHook(true));

@NgModule({
providers: [${usesZoneJS ? 'provideZoneChangeDetection(), ' : ''}...providers],
})
Expand Down
Loading