【问题标题】:widget test, testing a button with CircularProgressIndicator小部件测试,使用 CircularProgressIndicator 测试按钮
【发布时间】:2021-01-21 16:05:34
【问题描述】:

我有两个测试,在单击按钮后,我想测试 CircularProgressIndicator 是否会出现在按钮上。 问题是在点击和tester.pump()之后,它找不到导致测试失败的CircularProgressIndicator,我尝试使用pumpAndSettle()并添加了Duration(seconds:x),但得到了同样的错误

这很奇怪,因为在我将 flutter sdk 更新到 1.22.0、升级我的 flutterFire 包并迁移到使用 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);

    });
  });

【问题讨论】:

    标签: flutter testing widget-test-flutter


    【解决方案1】:

    有点晚了,但我也遇到了这个问题,我发现最短的解决方法只是尝试/捕获超时错误...

    try {
      await tester.pumpAndSettle();
    } catch (err) {}
    
    expect(find.byKey(financialDialogBillRequestButtonLoading), findsOneWidget);
    expect(find.byKey(financialDialogBillRequestButton), findsNothing);
    

    如果它可以在找到更好的解决方案之前帮助某人,我很高兴。

    【讨论】:

      猜你喜欢
      • 2022-12-13
      • 2019-12-27
      • 2019-02-25
      • 1970-01-01
      • 2019-06-13
      • 2019-04-28
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      相关资源
      最近更新 更多