-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests #56993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
|
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 |
|
This PR was merged into the repository by commit 3a63c9e. The changes were merged into the following branches: main, 18.1.x |
…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 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. |
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