Reputation: 7222
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>
Upvotes: 7
Views: 2454
Reputation: 616
This is what worked for me, I set ensureVisible()
first.
var foo = find.byKey(actionKey);
await tester.ensureVisible(foo); // <-- here
await tester.tap(foo);
await tester.pumpAndSettle();
Upvotes: -1
Reputation: 4738
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!
Upvotes: 3
Reputation: 1073
Try Waiting after tapping for like 2 seconds.
await tester.pump(Duration(seconds: 2));
I think it should work since it worked for me.
Upvotes: 0