MockGoRouter class

A stand-in GoRouter for widget tests that records every navigation call instead of building pages.

Wrap the widget under test with MockGoRouterProvider so that context.go, context.push and friends reach the mock:

final router = MockGoRouter(routes: {'user': '/users/:id'});

await tester.pumpWidget(
  MaterialApp(home: MockGoRouterProvider(router: router, child: const ProfileButton())),
);
await tester.tap(find.text('Open profile'));

expect(router.location, '/users/42');
expect(router.calls.last, const NavigationCall(NavigationKind.push, '/users/42'));
Inheritance
Implemented types
Available extensions

Constructors

MockGoRouter({String initialLocation = '/', Map<String, String> routes = const {}})
Creates a mock that starts at initialLocation.

Properties

backButtonDispatcher → BackButtonDispatcher
finalinherited
calls → List<NavigationCall>
Every navigation call, oldest first.
final
configuration ↔ RouteConfiguration
The route configuration used in go_router.
latefinalinherited
hashCode → int
The hash code for this object.
no setterinherited
location → String
The location on top of the stack.
no setter
observers → List<NavigatorObserver>?
The navigator observers used by GoRouter.
finalinherited
overridePlatformDefaultLocation → bool
Whether to ignore platform's default initial location when initialLocation is set.
finalinherited
routeInformationParser ↔ GoRouteInformationParser
The route information parser used by GoRouter.
latefinalinherited
routeInformationProvider ↔ GoRouteInformationProvider
The route information provider used by GoRouter.
latefinalinherited
routerDelegate ↔ GoRouterDelegate
The router delegate. Provide this to the MaterialApp or CupertinoApp's .router() constructor
latefinalinherited
routes → Map<String, String>
Route names mapped to path patterns, such as {'user': '/users/:id'}.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stack → List<String>
Every location on the stack, bottom first.
no setter
state → GoRouterState
The top GoRouterState, the state of the route that was last used in either GoRouter.go or GoRouter.push.
no setterinherited

Methods

canPop() → bool
Returns true if there is at least two or more route can be pop.
clearCalls() → void
Forgets all recorded calls.

Available on GoRouter, provided by the JugnuRoutes extension

A DeepLinkGenerator for this router's routes.
describeRoutes() → List<RouteInfo>

Available on GoRouter, provided by the JugnuRoutes extension

The router's routes as RouteInfo, with shell routes flattened away.
dispose() → void
Disposes resource created by this object.
inherited
go(String location, {Object? extra}) → void
Navigate to a URI location w/ optional query parameters, e.g. /family/f2/person/p1?color=blue
goNamed(String name, {Map<String, String> pathParameters = const {}, Map<String, dynamic> queryParameters = const {}, Object? extra, String? fragment}) → void
Navigate to a named route w/ optional parameters, e.g. name='person', pathParameters={'fid': 'f2', 'pid': 'p1'} Navigate to the named route.
namedLocation(String name, {Map<String, String> pathParameters = const {}, Map<String, dynamic> queryParameters = const {}, String? fragment}) → String
Get a location from route name and parameters. This is useful for redirecting to a named location.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pop<T extends Object?>([T? result]) → void
Pop the top-most route off the current screen.
push<T extends Object?>(String location, {Object? extra}) → Future<T?>
Push a URI location onto the page stack w/ optional query parameters, e.g. /family/f2/person/p1?color=blue.
pushNamed<T extends Object?>(String name, {Map<String, String> pathParameters = const {}, Map<String, dynamic> queryParameters = const {}, Object? extra}) → Future<T?>
Push a named route onto the page stack w/ optional parameters, e.g. name='person', pathParameters={'fid': 'f2', 'pid': 'p1'}
pushReplacement<T extends Object?>(String location, {Object? extra}) → Future<T?>
Replaces the top-most page of the page stack with the given URL location w/ optional query parameters, e.g. /family/f2/person/p1?color=blue.
pushReplacementNamed<T extends Object?>(String name, {Map<String, String> pathParameters = const {}, Map<String, dynamic> queryParameters = const {}, Object? extra}) → Future<T?>
Replaces the top-most page of the page stack with the named route w/ optional parameters, e.g. name='person', pathParameters={'fid': 'f2', 'pid': 'p1'}.
refresh() → void
Refresh the route.
replace<T>(String location, {Object? extra}) → Future<T?>
Replaces the top-most page of the page stack with the given one but treats it as the same page.
replaceNamed<T>(String name, {Map<String, String> pathParameters = const {}, Map<String, dynamic> queryParameters = const {}, Object? extra}) → Future<T?>
Replaces the top-most page with the named route and optional parameters, preserving the page key.
restore(RouteMatchList matchList) → void
Restore the RouteMatchList
inherited
stubResult(String location, Object? result) → void
Makes a push to location complete right away with result, as if the pushed page had popped with it.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited