我有一个这样的小部件测试,我可以用 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/