I am writing widget tests in Flutter. I am not able to find any documentation to execute "Go Back to Prevoius Screen" as I do not find any method for that. Please help with some sample "test" code for the same.
You have to mock navigation observer.
First create class class MockNavigatorObserver extends Mock implements NavigatorObserver
Declare final mockObserver = MockNavigatorObserver();
in your test file.
Put your widget inside MaterialApp
and add property navigatorObservers: [mockObserver],
Finally inside your testWidgets block {} mock like this:
final mockObserver = MockNavigatorObserver();
final backIcon = find.byIcon(Icons.arrow_back_ios);
expect(backIcon, findsOneWidget);
await tester.tap(backIcon);
verify(mockObserver.didPop(any, any));
await tester.pumpAndSettle();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With