我正在尝试测试自定义抽屉,但发现在测试中很难打开它,开始尝试以下操作,甚至这个测试也没有通过。错误是:Bad state: no element
。
void main() {
testWidgets('my drawer test', (WidgetTester tester) async {
final displayName = "displayName";
var drawKey = UniqueKey();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
drawer: Drawer(key: drawKey, child: Text(displayName),),
)));
await tester.tap(find.byKey(drawKey));
expect(find.text(displayName), findsOneWidget);
});
}