-
Notifications
You must be signed in to change notification settings - Fork 26.3k
feat(core): rethrow errors during ApplicationRef.tick in TestBed #57200
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
4a5b5a0
to
d37f8b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one minor comment.
57123fe
to
714cdfc
Compare
Errors during change detection from `ApplicationRef.tick` are only reported to the `ErrorHandler`. By default, this only logs the error to console. As a result, these errors can be missed/ignored and allow tests to pass when they should not. This change ensures that the errors are surfaced. Note that this is already the behavior when zoneless is enabled. BREAKING CHANGE: Errors that are thrown during `ApplicationRef.tick` will now be rethrown when using `TestBed`. These errors should be resolved by ensuring the test environment is set up correctly to complete change detection successfully. There are two alternatives to catch the errors: * Instead of waiting for automatic change detection to happen, trigger it synchronously and expect the error. For example, a jasmine test could write `expect(() => TestBed.inject(ApplicationRef).tick()).toThrow()` * `TestBed` will reject any outstanding `ComponentFixture.whenStable` promises. A jasmine test, for example, could write `expectAsync(fixture.whenStable()).toBeRejected()`. As a last resort, you can configure errors to _not_ be rethrown by setting `rethrowApplicationErrors` to `false` in `TestBed.configureTestingModule`.
714cdfc
to
cf7f761
Compare
caretaker note: This will need an update to catalyst since the private option is renamed and made public: cl/660852548 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-for: public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
This PR was merged into the repository by commit 468d3fb. The changes were merged into the following branches: main |
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. |
Errors during change detection from
ApplicationRef.tick
are onlyreported to the
ErrorHandler
. By default, this only logs the error toconsole. As a result, these errors can be missed/ignored and allow tests
to pass when they should not. This change ensures that the errors are
surfaced. Note that this is already the behavior when zoneless is
enabled.
The rethrowing behavior will be the default in v19.
BREAKING CHANGE: Errors that are thrown during
ApplicationRef.tick
will now be rethrown when using
TestBed
. These errors should beresolved by ensuring the test environment is set up correctly to
complete change detection successfully. There are two alternatives to
catch the errors:
it synchronously and expect the error. For example, a jasmine test
could write
expect(() => TestBed.inject(ApplicationRef).tick()).toThrow()
TestBed
will reject any outstandingComponentFixture.whenStable
promises. A jasmine test,for example, could write
expectAsync(fixture.whenStable()).toBeRejected()
.As a last resort, you can configure errors to not be rethrown by
setting
rethrowApplicationErrors
tofalse
inTestBed.configureTestingModule
.