widget test, testing a button with CircularProgressIndicator

987 views Asked by At

I have two tests that after a click on a button I want to test if a CircularProgressIndicator will appear on the button. The problem is after the tap and the tester.pump(), it can't find the CircularProgressIndicator causing the test to fail, I tried with pumpAndSettle() and also add a Duration(seconds:x) but got the same error

It's weird because the tests were ok before I update the flutter sdk to 1.22.0, upgrade my flutterFire packages and migrate to use the Android embbeding V2.

testWidgets("Should show loading button when click on request button ",
        (WidgetTester tester) async {
      await tester.pumpWidget(
        _buildWidget(
          home: FinancialDialogBill(
            paymentId: "fakePaymentId",
            additionalValueType: AdditionalValueType.fee,
            billValues: billValues,
            installmentList: installments,
          ),
        ),
      );

      expect(find.byKey(financialDialogBillRequestButton), findsOneWidget);
      expect(find.byKey(financialDialogBillRequestButtonLoading), findsNothing);

      await tester.tap(find.byKey(financialDialogBillRequestButton));

      await tester.pump();

      expect(
          find.byKey(financialDialogBillRequestButtonLoading), findsOneWidget);
      expect(find.byKey(financialDialogBillRequestButton), findsNothing);

    });
  });

1

There are 1 answers

0
JulienV On

A bit late, but i ran into this issue as well, the shortest workaround i found i just to try/catch the timeout error...

try {
  await tester.pumpAndSettle();
} catch (err) {}

expect(find.byKey(financialDialogBillRequestButtonLoading), findsOneWidget);
expect(find.byKey(financialDialogBillRequestButton), findsNothing);

Happy if it can help someone before a better solution is found.