Open mrverdant13 opened 9 months ago
Hey @mrverdant13 you probably need to add a RouterScope
to your testing tree as well
+1 PagelessRoutesObserver class is not actually exposed by the package itself to make mock of StackRouter for RouterScope and StackRouterScope.
Is there any solutions? @Milad-Akarie
Example:
import 'package:auto_route/src/router/controller/pageless_routes_observer.dart'; // BAD BAD LINE
// Mock auto_route router stack
class MockR extends Mock implements StackRouter {
@override
PagelessRoutesObserver pagelessRoutesObserver = PagelessRoutesObserver();
@override
bool canPop({bool ignoreChildRoutes = false, bool ignoreParentRoutes = false, bool ignorePagelessRoutes = false}) {
return true;
}
}
Widget stackRouterWrap(Widget child) {
return RouterScope(
controller: MockR(),
stateHash: 0,
inheritableObserversBuilder: () => [],
child: StackRouterScope(
controller: MockR(),
stateHash: 0,
child: child,
),
);
}
Hi 👋🏼
I am trying to test an
AutoLeadingButton
as follows:This approach works just fine for other navigation-related tests, but it throws the following exception when used for the
AutoLeadingButton
:After reviewing the
AutoLeadingButton
implementation, I found this:So I tried to update the test code as required, but seems like the
PagelessRoutesObserver
class is not actually exposed by the package itself, so this would make theAutoLeadingButton
widget completely untestable, nor by mocking the class nor by bypassing the access to that instance.Is there anything that I am missing here? Is there any other alternative to test this widget?