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

A Timer is still pending even after the widget tree was disposed #35

Open
AhmedHathout opened this issue Sep 3, 2024 · 1 comment
Open

Comments

@AhmedHathout
Copy link

Hi, I am facing a problem with widget tests. If the widget I am testing has a UseQueryResult, the test fails because of a pending timer. Here is the stack trace:-

Pending timers:
Timer (duration: 0:03:00.000000, periodic: false), created:
#0      new FakeTimer._ (package:fake_async/fake_async.dart:308:62)
#1      FakeAsync._createTimer (package:fake_async/fake_async.dart:252:27)
...
...
...
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
A Timer is still pending even after the widget tree was disposed.
'package:flutter_test/src/binding.dart':
Failed assertion: line 1542 pos 12: '!timersPending'

When the exception was thrown, this was the stack:
#2      AutomatedTestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:1542:12)
#3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1049:7)
<asynchronous suspension>
<asynchronous suspension>
(elided 3 frames from class _AssertionError and package:stack_trace)

It looks like it is because of the cacheDuration (the one that if I change its value, the second line in the stack trace I provided change). I tried to set the cacheDuration to 0 but I get the same error. Is there a way to either dispose that timer (and other timers if there are any) or not creating it in tests from the beginning?

@AhmedHathout
Copy link
Author

Any advice on how to fix this one?

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

1 participant