flutter - 如何在颤振测试中模拟 onDoubleTap
问题描述
我正在尝试编写颤振测试并模拟双标签。但我无法设法找到方法。
这是我现在所做的:
void main() {
testWidgets('It should trigger onDoubleTap', (tester) async {
await tester.pumpWidget(MaterialApp(
home: GestureDetector(
child: const Text('button'),
onDoubleTap: () {
print('double tapped');
},
),
));
await tester.pumpAndSettle();
await tester.tap(find.text('button')); // <- Tried with tester.press too
await tester.tap(find.text('button')); // <- Tried with tester.press too
await tester.pumpAndSettle();
});
}
当我运行测试时,这是我得到的:
00:03 +1: All tests passed!
但我double tapped
在控制台中看不到任何内容。
如何触发双击?
解决方案
kDoubleTapMinTime
解决方案是在两个水龙头之间等待。
void main() {
testWidgets('It should trigger onDoubleTap', (tester) async {
await tester.pumpWidget(MaterialApp(
home: GestureDetector(
child: const Text('button'),
onDoubleTap: () {
print('double tapped');
},
),
));
await tester.pumpAndSettle();
await tester.tap(find.text('button'));
await tester.pump(kDoubleTapMinTime); // <- Add this
await tester.tap(find.text('button'));
await tester.pumpAndSettle();
});
}
我double tapped
在控制台中得到:
double tapped
00:03 +1: All tests passed!
推荐阅读
- ruby - 如何在使用 Docker 安装的 Jenkins 中保存已安装的 gem?
- javascript - 在Javascript中用空格在数组中添加一个字段
- javascript - 获取基于给定数据和时间的时间段,每 15 分钟 jQuery
- asp.net-core - 如何修复 Obj 文件夹程序集错误:“可执行文件不能是附属程序集;区域性应始终为空”
- amazon-cognito - 在“allowedOAuthFlows”处获取值“[Token]”未能满足约束错误
- c# - SpreadsheetGear 更新后 IWorkbook.GetDataSet 不起作用
- neural-network - 使用感知器在或门中得到错误的 [1,0] 输出
- angular - 如何在Angular 8中用相同的事件中断先前的发射
- laravel - Laravel 6 - 验证唯一,忽略两个条件 - 相同的用户和名称。更新时 $this->id 也为空
- java - 如何在同一个类中调用Java中的方法和system.out.print结果