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

Fails in tests #11

Open
joshpetit opened this issue Dec 16, 2021 · 1 comment
Open

Fails in tests #11

joshpetit opened this issue Dec 16, 2021 · 1 comment

Comments

@joshpetit
Copy link

Hey! So I'm using marquee in my project, and have realized that it's causing some of my tests to fail. I didn't realize it was the reason until I added it to a widget in tests that already passed causing them to fail. This is the error output so I was wondering if you could give some guidance on how to work around this:

Timer (duration: 0:00:01.000000, periodic: false), created:
#0      new FakeTimer._ (package:fake_async/fake_async.dart:284:41)
#1      FakeAsync._createTimer (package:fake_async/fake_async.dart:248:27)
#2      FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:181:19)
#6      Marquee.scroll (package:marquee_widget/marquee_widget.dart:54:22)
<asynchronous suspension>
(elided 3 frames from dart:async)
Pending timers:
Timer (duration: 0:00:01.000000, periodic: false), created:
#0      new FakeTimer._ (package:fake_async/fake_async.dart:284:41)
#1      FakeAsync._createTimer (package:fake_async/fake_async.dart:248:27)
#2      FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:181:19)
#6      Marquee.scroll (package:marquee_widget/marquee_widget.dart:54:22)
#7      Marquee.build (package:marquee_widget/marquee_widget.dart:62:5)
#8      StatelessElement.build (package:flutter/src/widgets/framework.dart:4662:28)
#9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4588:15)
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#11     StatelessElement.update (package:flutter/src/widgets/framework.dart:4669:5)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#13     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5626:32
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 1236 pos 12: '!timersPending'

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

I just took those snippets since the actual error message is pretty long 😅.

Some help getting around this would be awesome since I would still love to use this library! Thanks.

@Gorniv
Copy link
Contributor

Gorniv commented Oct 7, 2022

try https://pub.dev/packages/fake_async :

 final fakeAsync = FakeAsync();
    unawaited(
      fakeAsync.run(
        (async) async {
          await func();
        },
      ),
    );
    fakeAsync.flushMicrotasks();

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