Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test pushed route with Modular #919

Open
3ph opened this issue Nov 30, 2023 · 0 comments
Open

How to test pushed route with Modular #919

3ph opened this issue Nov 30, 2023 · 0 comments
Labels
new New issue request attention question Questions about using some feature or general working of the package

Comments

@3ph
Copy link

3ph commented Nov 30, 2023

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 3ph added new New issue request attention question Questions about using some feature or general working of the package labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention question Questions about using some feature or general working of the package
Projects
None yet
Development

No branches or pull requests

1 participant