InkWell tap 的 Flutter 小部件测试失败

标签 flutter widget-test-flutter

我有一个这样的小部件测试,我可以用 actionKey 找到小部件,但敲击测试失败且 tapped tester.tap(...) 之后的值为假,我的测试有什么问题?

testWidgets('some test', (WidgetTester tester) async {
  final UniqueKey actionKey = UniqueKey();
  bool tapped = false;

  await tester.pumpWidget(MaterialApp(
    home: Scaffold(
      body: SlidableListItem(
        child: const ListTile(title: Text('item')),
        actions: <Widget>[
          InkWell(
            key: actionKey,
            child: const Text('action'),
            onTap: () => tapped = true,
          ),
        ],
      ),
    ),
  ));

  await tester.tap(find.byKey(actionKey));
  await tester.pump();

  expect(find.byKey(actionKey), findsOneWidget);
  expect(tapped, isTrue); <- failes
});
The following TestFailure object was thrown running a test:
  Expected: true
  Actual: <false>

最佳答案

点击 2 秒后尝试等待。

      await tester.pump(Duration(seconds: 2));
我认为它应该有效,因为它对我有用。

关于InkWell tap 的 Flutter 小部件测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63450630/

相关文章:

flutter - Codemagic:如何设置集成测试 Android 模拟器

amazon-web-services - Flutter 中的 AWS SNS

dart - Flutter中的弧形渐变?

list - 在 flutter 中从一个屏幕转到另一个屏幕时如何不丢失列表中的数据?

Flutter 模拟 ChangeNotifierProvider 并设置提供程序值

flutter - 如何在 Flutter 中测试 LongPressDraggable

flutter - 如何在 Flutter 测试中找到 `FlatButton.icon`?

android - AAPT : error: attribute fastforward_increment (aka aplicationid. dev:fastforward_increment) 未找到

xcode - Flutters video_editor 示例的 Pod 安装失败

flutter 测试: Look for a widget inside of another widget