fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests#56993
Closed
atscott wants to merge 1 commit intoangular:mainfrom
Closed
fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests#56993atscott wants to merge 1 commit intoangular:mainfrom
atscott wants to merge 1 commit intoangular:mainfrom
Conversation
094a528 to
7724bc9
Compare
…oneless tests The behavior of `ComponentFixture` for zoneless tests was decided somewhat through guesswork, trial, and error. In addition, working on the zoneless fixture revealed oddities in the behavior of the zone-based fixture, or behaviors that we felt were counterintuitive. The most consequential difference is how change detection works: `detectChanges` goes through ApplicationRef.tick in zoneless while it is `changeDetectorRef.detectChanges` in the zone fixture. We felt that running change detection through `ApplicationRef.tick` was important for several reasons: * Aligning application behavior more closely with the test behavior (almost all views are attached to application ref in reality) * Ensuring that afterRender* hooks are executed when calling `fixture.detectChanges` * Ensuring that the change detection runs again if render hooks update state This change, however, has some noticeable consequences that will break some tests, mostly around how errors are handled. `ApplicationRef.tick` catches errors that happen during change detection and reports them to the ErrorHandler from DI. The default error handler only logs the error to the console. This will break tests which have `expect(() => fixture.detectChanges()).toThrow()`. In addition, it allows tests to pass when there are real errors encountered during change detection. This change ensures that errors from `ApplicationRef.tick` are rethrown and will fail the test. We should also do a follow-up investigation to determine whether we can/should also do this for the zone-based `ComponentFixture`. fixes angular#56977
7724bc9 to
6ba156e
Compare
Contributor
Author
|
I also tested this change for zone-based fixtures as well. There are ~200 failures in TGP that truly have errors that just result in |
pkozlowski-opensource
approved these changes
Jul 26, 2024
Contributor
|
This PR was merged into the repository by commit 3a63c9e. The changes were merged into the following branches: main, 18.1.x |
dylhunn
pushed a commit
that referenced
this pull request
Jul 29, 2024
…oneless tests (#56993) The behavior of `ComponentFixture` for zoneless tests was decided somewhat through guesswork, trial, and error. In addition, working on the zoneless fixture revealed oddities in the behavior of the zone-based fixture, or behaviors that we felt were counterintuitive. The most consequential difference is how change detection works: `detectChanges` goes through ApplicationRef.tick in zoneless while it is `changeDetectorRef.detectChanges` in the zone fixture. We felt that running change detection through `ApplicationRef.tick` was important for several reasons: * Aligning application behavior more closely with the test behavior (almost all views are attached to application ref in reality) * Ensuring that afterRender* hooks are executed when calling `fixture.detectChanges` * Ensuring that the change detection runs again if render hooks update state This change, however, has some noticeable consequences that will break some tests, mostly around how errors are handled. `ApplicationRef.tick` catches errors that happen during change detection and reports them to the ErrorHandler from DI. The default error handler only logs the error to the console. This will break tests which have `expect(() => fixture.detectChanges()).toThrow()`. In addition, it allows tests to pass when there are real errors encountered during change detection. This change ensures that errors from `ApplicationRef.tick` are rethrown and will fail the test. We should also do a follow-up investigation to determine whether we can/should also do this for the zone-based `ComponentFixture`. fixes #56977 PR Close #56993
This was referenced Aug 22, 2024
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The behavior of
ComponentFixturefor zoneless tests was decided somewhat through guesswork, trial, and error. In addition, working on the zoneless fixture revealed oddities in the behavior of the zone-based fixture, or behaviors that we felt were counterintuitive. The most consequential difference is how change detection works:detectChangesgoes through ApplicationRef.tick in zoneless while it ischangeDetectorRef.detectChangesin the zone fixture.We felt that running change detection through
ApplicationRef.tickwas important for several reasons:fixture.detectChangesThis change, however, has some noticeable consequences that will break some tests, mostly around how errors are handled.
ApplicationRef.tickcatches errors that happen during change detection and reports them to the ErrorHandler from DI. The default error handler only logs the error to the console. This will break tests which haveexpect(() => fixture.detectChanges()).toThrow(). In addition, it allows tests to pass when there are real errors encountered during change detection.This change ensures that errors from
ApplicationRef.tickare rethrown and will fail the test. We should also do a follow-up investigation to determine whether we can/should also do this for the zone-basedComponentFixture.fixes #56977