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

Pending timer exception on widget test #319

Open
jv-soares opened this issue Aug 3, 2023 · 0 comments
Open

Pending timer exception on widget test #319

jv-soares opened this issue Aug 3, 2023 · 0 comments

Comments

@jv-soares
Copy link

Im getting the following exception whenever writing a simple widget test for the speed dial

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 1498 pos 12: '!timersPending'

Here is the widget test

void main() {
  testWidgets('should find speed dial', (widgetTester) async {
    await widgetTester.pumpWidget(
      const MaterialApp(
        home: Scaffold(floatingActionButton: SpeedDial()),
      ),
    );

    final finder = find.byType(SpeedDial);

    expect(finder, findsOneWidget);
  });
}

And here is the full log message

Pending timers:
Timer (duration: 0:00: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)
#2      FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:185:19)
#6      _SpeedDialState.initState (package:flutter_speed_dial/src/speed_dial.dart:243:12)
#7      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5219:55)
#8      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062:5)
...     Normal element mounting (23 frames)
#31     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#32     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#33     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (21 frames)
#54     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#55     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#56     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (324 frames)
#380    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#381    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#382    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (435 frames)
#817    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#818    Element.updateChild (package:flutter/src/widgets/framework.dart:3702:20)
#819    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#820    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#821    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#822    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#823    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#824    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)
#825    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#826    StatefulElement.update (package:flutter/src/widgets/framework.dart:5274:5)
#827    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#828    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#829    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#830    ProxyElement.update (package:flutter/src/widgets/framework.dart:5417:5)
#831    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#832    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#833    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#834    StatelessElement.update (package:flutter/src/widgets/framework.dart:5162:5)
#835    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#836    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1240:16)
#837    RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1217:5)
#838    RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1231:7)
#839    Element.rebuild (package:flutter/src/widgets/framework.dart:4805:7)
#840    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2780:19)
#841    AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1386:19)
#842    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:358:5)
#843    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1284:15)
#844    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1214:9)
#845    AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:1236:9)
#848    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:68:41)
#849    AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:1222:27)
#850    WidgetTester._pumpWidget (package:flutter_test/src/widget_tester.dart:592:20)
#851    WidgetTester.pumpWidget.<anonymous closure> (package:flutter_test/src/widget_tester.dart:577:14)
#854    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:68:41)
#855    WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:576:27)
#856    main.<anonymous closure> (file:///Users/aparkado/dev/apps_flutter/lkw_app/test/speed_dial_test.dart:7:24)
#857    testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:170:29)
<asynchronous suspension>
<asynchronous suspension>
(elided 8 frames from dart:async and package:stack_trace)

══╡ 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 1498 pos 12: '!timersPending'

When the exception was thrown, this was the stack:
#2      AutomatedTestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:1498:12)
#3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1003:7)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)
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