我有一个 PaginatedDataTable,它有一个带有 PopupMenuButton 的 DataCell。WidgetTester 可以找到每个 DataCell 没问题,但我似乎无法引用 PopupMenuButton 的项目来尝试选择一个。
如何在单元测试中获取 PopupMenuButton 的 PopupMenuItem 文本?我await tester.pump();
是否正确使用以允许菜单出现?
这是我现在的做法:
...
expect(find.byIcon(Icons.more_horiz).first, findsOneWidget); // works!
await tester.tap(find.byIcon(Icons.more_horiz).first);
await tester.pump();
var byType = find.text('Quote');
expect(byType, findsOneWidget); // fails!
哪个失败了
zero widgets with text "Quote" (ignoring offstage widgets)...
这是 DataCell 标记
...
new DataCell(...),
new DataCell(new PopupMenuButton<quickActions>(
icon: new Icon(Icons.more_horiz),
onSelected: (quickActions action) {
_selectContextAction(action);
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<quickActions>>[
new PopupMenuItem<quickActions>(
value: quickActions.edit,
child: new Text('Edit'),
),
new PopupMenuItem<quickActions>(
value: quickActions.remove,
child: new Text('Remove'),
),
new PopupMenuItem<quickActions>(
value: quickActions.reschedule,
child: new Text('Re-schedule'),
),
new PopupMenuItem<quickActions>(
value: quickActions.bid,
child: new Text('Quote'),
),
],
))