Flare-flutter: Widget testing with FlareActor

Created on 10 Jul 2019  ยท  4Comments  ยท  Source: 2d-inc/Flare-Flutter

flutter: 1.5.4-hotfix.2
flare_flutter: 1.5.2

Hi, I'm attempting to run basic widget tests on pages that include a FlareActor, which result in the following error:

โ•โ•โ•ก 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 1014 pos 7:
'_currentFakeAsync.nonPeriodicTimerCount == 0'

Here is the flutter test I'm running:

import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Widget makeTestableWidget() {
  return MaterialApp(
    home: Scaffold(
      body: Stack(
        children: <Widget>[
          FlareActor(
            "assets/images/tick.flr",
            alignment: Alignment.center,
            fit: BoxFit.contain,
            animation: "success",
          ),
          Text('Success'),
        ],
      ),
    ),
  );
}

void main() {
  group('Flare widget', () {
    testWidgets('renders correctly', (WidgetTester tester) async {
      await tester.pumpWidget(makeTestableWidget());

      expect(find.text('Success'), findsOneWidget);
    });
  });
}

Is there a suggested way to allow these tests to complete? As a workaround I've been navigating away from the page allowing the FlareActor to be disposed and the test to complete, but just wondering if there is a better way to test widgets containing FlareActors.

I believe this may be the same issue as mentioned in a comment in #69

Thanks

Most helpful comment

Take a look at this response in a similar issue: https://github.com/2d-inc/Flare-Flutter/issues/160#issuecomment-538603844

All 4 comments

I am able to build the widget for testing, but it doesn't ever call initialize for the controller. So I have basic unit tests to see if there is a widget, but I can't test anything with the animations because the art board never gets initialized.

Take a look at this response in a similar issue: https://github.com/2d-inc/Flare-Flutter/issues/160#issuecomment-538603844

@luigi-rosso
That worked perfectly! Thanks so much!

@luigi-rosso how would you go about generating more flares? So i am able to initialize the flare and compare that to a golden. But I can't seem to get the animation to run again to change the tested animation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tsinis picture tsinis  ยท  3Comments

gabber235 picture gabber235  ยท  6Comments

nisimjoseph picture nisimjoseph  ยท  4Comments

lukepighetti picture lukepighetti  ยท  5Comments

stx picture stx  ยท  6Comments