Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Jul 30, 2024

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.

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 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.

@atscott atscott added area: testing Issues related to Angular testing features, such as TestBed breaking changes area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Jul 30, 2024
@ngbot ngbot bot added this to the Backlog milestone Jul 30, 2024
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Jul 30, 2024
@atscott atscott force-pushed the rethrowErrorsDefault branch from 4a5b5a0 to d37f8b0 Compare July 30, 2024 23:21
@atscott atscott requested a review from AndrewKushnir July 30, 2024 23:22
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a 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.

@atscott atscott force-pushed the rethrowErrorsDefault branch from 57123fe to 714cdfc Compare August 1, 2024 22:00
@angular-robot angular-robot bot added detected: feature PR contains a feature commit and removed detected: breaking change PR contains a commit with a breaking change labels Aug 1, 2024
@atscott atscott changed the title fix(core): Errors during ApplicationRef.tick should be rethrown in te… feat(core): Add config to rethrow errors during ApplicationRef.tick in TestBed Aug 1, 2024
@atscott atscott added target: minor This PR is targeted for the next minor release breaking changes target: major This PR is targeted for the next major release and removed breaking changes target: major This PR is targeted for the next major release target: minor This PR is targeted for the next minor release labels Aug 1, 2024
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`.
@atscott atscott force-pushed the rethrowErrorsDefault branch from 714cdfc to cf7f761 Compare August 1, 2024 22:04
@atscott atscott changed the title feat(core): Add config to rethrow errors during ApplicationRef.tick in TestBed feat(core): rethrow errors during ApplicationRef.tick in TestBed Aug 1, 2024
@angular-robot angular-robot bot added detected: breaking change PR contains a commit with a breaking change and removed detected: feature PR contains a feature commit labels Aug 1, 2024
@atscott atscott added the action: global presubmit The PR is in need of a google3 global presubmit label Aug 8, 2024
@atscott
Copy link
Contributor Author

atscott commented Aug 12, 2024

TGP

@atscott atscott removed the action: global presubmit The PR is in need of a google3 global presubmit label Aug 12, 2024
@atscott
Copy link
Contributor Author

atscott commented Aug 12, 2024

caretaker note: This will need an update to catalyst since the private option is renamed and made public: cl/660852548

@atscott atscott added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Aug 12, 2024
@pullapprove pullapprove bot requested a review from AndrewKushnir August 12, 2024 18:17
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a 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

Copy link
Contributor

@thePunderWoman thePunderWoman left a 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

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 468d3fb.

The changes were merged into the following branches: main

@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 Sep 12, 2024
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: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed breaking changes detected: breaking change PR contains a commit with a breaking change merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants