modular icon indicating copy to clipboard operation
modular copied to clipboard

How to test pushed route with Modular

Open 3ph opened this issue 1 year ago • 0 comments

Documentation describes how to use IModularNavigator to intercept navigation calls but I'm not sure how to test that the correct route was pushed.

class ModularNavigateMock extends Mock implements IModularNavigator {}

...

testWidgets('delivery address list component (navigation)...',
      (tester) async {
    
    Modular.navigatorDelegate = ModularNavigateMock();;
    
    await tester.pumpWidget(...);

    await tester.tap(find.byType(InkWell).at(2));
    await tester.pumpAndSettle();
    expect(find.byType(EditAddressModal), findsOneWidget);
});

The tap invokes this action:

void _onEditAddressTapped({required AddressDataModel addressModel}) {
    Modular.to.push(
      MaterialPageRoute<Null>(
          builder: (BuildContext context) {
            return EditAddressModal(addressModel: addressModel);
          },
          fullscreenDialog: true),
    );
  }

The test fails however if I use Navigator.of(context).push(...) and Mocktail's NavigatorObserver mock the test succeeds.

Is there a way how to achieve this with Modular?

3ph avatar Nov 30 '23 09:11 3ph