Skip to content

fix(@angular/build): ensure TestBed cleanup hooks are always registered#31814

Merged
clydin merged 1 commit intoangular:mainfrom
clydin:unit-test/always-testbed-hooks
Nov 14, 2025
Merged

fix(@angular/build): ensure TestBed cleanup hooks are always registered#31814
clydin merged 1 commit intoangular:mainfrom
clydin:unit-test/always-testbed-hooks

Conversation

@clydin
Copy link
Member

@clydin clydin commented Nov 14, 2025

This commit moves the beforeEach and afterEach hook registrations for TestBed cleanup to be outside the global setup guard.

In environments where test isolation is not strictly enforced (when isolate: false), the setup file can be executed multiple times in different contexts. The global guard would previously prevent the hooks from being re-registered, leading to inconsistent test behavior and potential state leakage between tests.

This change ensures the cleanup hooks are always registered, improving the reliability and predictability of tests across all execution environments.

This commit moves the `beforeEach` and `afterEach` hook registrations for TestBed cleanup to be outside the global setup guard.

In environments where test isolation is not strictly enforced (when `isolate: false`), the setup file can be executed multiple times in different contexts. The global guard would previously prevent the hooks from being re-registered, leading to inconsistent test behavior and potential state leakage between tests.

This change ensures the cleanup hooks are always registered, improving the reliability and predictability of tests across all execution environments.
@clydin clydin added the target: rc This PR is targeted for the next release-candidate label Nov 14, 2025
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 14, 2025
@clydin clydin requested a review from alan-agius4 November 14, 2025 16:05
@clydin clydin removed the request for review from alan-agius4 November 14, 2025 17:08
@clydin clydin removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 14, 2025
@hybrist hybrist added the action: merge The PR is ready for merge by the caretaker label Nov 14, 2025
@clydin clydin merged commit 79e52cc into angular:main Nov 14, 2025
178 of 185 checks passed
@clydin
Copy link
Member Author

clydin commented Nov 14, 2025

This PR was merged into the repository. The changes were merged into the following branches:

@clydin clydin deleted the unit-test/always-testbed-hooks branch November 14, 2025 19:08
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants