NyMockRouteGuard class
A mock route guard for testing NyPage route guard behavior.
Use NyMockRouteGuard.pass to create a guard that allows navigation, or NyMockRouteGuard.redirect to create one that redirects.
Example
// A guard that always passes
final guard = NyMockRouteGuard.pass();
// A guard that redirects to login
final guard = NyMockRouteGuard.redirect('/login');
// A guard with custom logic
final guard = NyMockRouteGuard.custom((context) async {
if (someCondition) return GuardResult.next;
return GuardResult.handled;
});
// Check if the guard was called
expect(guard.wasCalled, isTrue);
expect(guard.callCount, 1);
- Inheritance
-
- Object
- RouteGuard
- NyRouteGuard
- NyMockRouteGuard
Constructors
-
NyMockRouteGuard.custom(Future<
GuardResult> handler(RouteContext context)) -
Create a guard with custom logic.
factory
- NyMockRouteGuard.pass()
-
Create a guard that always allows navigation to continue.
factory
- NyMockRouteGuard.redirect(String path, {dynamic data})
-
Create a guard that always redirects to
path.factory
Properties
- callCount → int
-
The number of times this guard has been called.
no setter
- context → BuildContext?
-
Convenience getter for the build context.
no setterinherited
- data → dynamic
-
Convenience getter for the route data.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasModifiedData → bool
-
Whether setData was called during this guard's execution.
no setterinherited
- lastContext → RouteContext?
-
The RouteContext from the most recent call, or null if never called.
no setter
- modifiedData → dynamic
-
Get modified data if setData was called.
no setterinherited
- pageRequest ↔ PageRequest?
-
getter/setter pairinherited
-
queryParameters
→ Map<
String, String> -
Convenience getter for query parameters.
no setterinherited
- redirectConfig → RedirectConfig?
-
Get the redirect configuration if a redirect was requested.
no setterinherited
- routeContext → RouteContext?
-
The current route context.
no setterinherited
- routeName → String?
-
Convenience getter for the route name.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- wasCalled → bool
-
Whether this guard has been called at least once.
no setter
Methods
-
abort(
) → GuardResult -
Abort navigation without redirecting.
inherited
-
next(
) → GuardResult -
Continue to the next guard or to the route.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAfter(
RouteContext context) → Future< void> -
Called after successful navigation to the route.
inherited
-
onBefore(
RouteContext context) → Future< GuardResult> -
Called before navigation to the route.
override
-
onRequest(
PageRequest pageRequest) → Future< PageRequest?> -
Legacy method override for backward compatibility.
Delegates to the new onBefore lifecycle method.
inherited
-
redirect(
Object path, {dynamic data, Map< String, dynamic> ? queryParameters, dynamic result, bool removeUntilPredicate(Route route)?, TransitionType? transitionType, dynamic onPop(dynamic value)?}) → GuardResult -
Redirect to a different route.
inherited
-
reset(
) → void - Reset the call tracking state.
-
setData(
dynamic data) → void -
Modify the data passed to subsequent guards and the route.
inherited
-
setRouteContext(
RouteContext context) → void -
Set the route context. Called by the router.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited