Ham*_*med 7 flutter widget-test-flutter
我有一个像这样的小部件测试,我可以使用 找到小部件actionKey,但是点击测试失败并且tapped在 后值为 false 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
});
Run Code Online (Sandbox Code Playgroud)
The following TestFailure object was thrown running a test:
Expected: true
Actual: <false>
Run Code Online (Sandbox Code Playgroud)
小部件的评估对我有用。
InkWell InkWellButton() => find
.byKey(actionKey)
.evaluate()
.first
.widget;
Run Code Online (Sandbox Code Playgroud)
然后对 Inkwell 进行操作即可。
InkWellButton().onTap();
await tester.pumpAndSettle();
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
2113 次 |
| 最近记录: |