angular/packages/core
Andrew Scott 3a63c9ebbe fix(core): errors during ApplicationRef.tick should be rethrown for zoneless 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
2024-07-29 13:49:00 -07:00
..
global docs(docs-infra): Add missing API entries to ADEV (#54530) 2024-02-21 16:41:33 +00:00
primitives refactor(core): Switch to using concat rather than spread operator for events. (#57103) 2024-07-23 15:54:23 -07:00
reference-manifests build: add target to generate api manifest (#52472) 2023-11-02 11:00:59 -07:00
rxjs-interop fix(core): tree shake dev mode error message (#57035) 2024-07-22 10:49:18 -07:00
schematics fix(migrations): remove unused imports in inject migration (#57179) 2024-07-29 13:47:14 -07:00
src fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests (#56993) 2024-07-29 13:49:00 -07:00
test fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests (#56993) 2024-07-29 13:49:00 -07:00
testing fix(core): errors during ApplicationRef.tick should be rethrown for zoneless tests (#56993) 2024-07-29 13:49:00 -07:00
BUILD.bazel refactor(docs-infra): complete removal of aio directory (#56496) 2024-06-18 12:26:00 -07:00
index.ts refactor(core): made comment structure consistent in index.ts (#43684) 2021-10-21 18:39:58 +00:00
package.json build: update Node.js to match Angular CLI engines (#56187) 2024-06-03 18:00:46 +00:00
PACKAGE.md docs: add package doc files (#26047) 2018-10-05 15:42:14 -07:00
public_api.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00