I have a widget test like this, I can find the widget with actionKey
, but the tapping test fails and tapped
value is false after tester.tap(...)
, what is wrong with my test?
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>
Evaluate of widget works for me.
InkWell InkWellButton() => find
.byKey(actionKey)
.evaluate()
.first
.widget;
and then action on Inkwell works.
InkWellButton().onTap();
await tester.pumpAndSettle();
Hope this helps!