我想测试一下,当我点击一个按钮时,用户会被路由到下一个页面。这在UI中有效。我引入了这个测试,但得到了以下错误:The following TestFailure object was thrown running a test: Expected: exactly one matching node in the widget tree Actual: _WidgetTypeFinder:<zero widgets with type "MyNextView" (ignoring offstage widgets)> Which: means none were found but one was expected
我做错了什么?
testWidgets('Button tap routes to next page', (WidgetTester tester) async {
final button = createButton();
await tester.pumpWidget(button);
await tester.tap(find.byWidget(button));
expect(find.byType(MyNextView), findsOneWidget);
});发布于 2020-10-30 03:14:10
之后>
等待按钮(find.byWidget(tester.tap));
放入这一行>
等待tester.pumpAndSettle();//等待屏幕更新
testWidgets('Button tap routes to next page', (WidgetTester tester) async {
final button = createButton();
await tester.pumpWidget(button);
await tester.tap(find.byWidget(button));
await tester.pumpAndSettle(); // Wait for screen to update
expect(find.byType(MyNextView), findsOneWidget);
});https://stackoverflow.com/questions/64592939
复制相似问题