Skip to content
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

Overrides on FlutterError.onError does not take effect. #409

Open
ye-yu opened this issue Dec 13, 2024 · 2 comments
Open

Overrides on FlutterError.onError does not take effect. #409

ye-yu opened this issue Dec 13, 2024 · 2 comments

Comments

@ye-yu
Copy link

ye-yu commented Dec 13, 2024

Describe the bug
Overrides on FlutterError.onError does not take effect. Overriding this error is useful for ignoring unnecessary errors.

To Reproduce

  1. Create a widget that throws error.
  2. Create a test that ignores this specific error using FlutterError.onError.
    FlutterError.onError = (error) {
      if (error is SpecificError) return;
      FlutterError.presentError(error);
    }
    addTearDown(() => FlutterError.onError = FlutterError.presentError;
  3. Error is not ignored as expected.

Expected behavior
FlutterError.onError should be called. If the condition matched, error is not reported.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Should I create a PR to remove this line or replace this with FlutterError.onError?

https://github.com/fzyzcjy/flutter_convenient_test/blob/master/packages/convenient_test_dev/lib/src/functions/widget_tester.dart#L191

Copy link

welcome bot commented Dec 13, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 13, 2024

Hmm, looks like we can directly do

convenientTestRunAsyncEnhancedExceptionChecker = (e) {
  if (e is SpecificError) return;
  expect(e, isNull);
}

to ensure we ignore the specific error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants