Stacked-Org / stacked

A Flutter application architecture created from real world scenarios
MIT License
946 stars 255 forks source link

[bug]: Stub and verify test in stacked navigation service. #1019

Open GameOnAnil opened 1 year ago

GameOnAnil commented 1 year ago

Describe the bug

I am trying to stub and verify popUntil() to write test for my viewmodel. @ferrarafer @FilledStacks Could you please explain how i would achieve this in stacked navigation service.

To reproduce

Here are the steps to reproduce this:

  1. In testhelpers
    MockNavigationService getAndRegisterNavigationService() {
    removeRegistrationIfExists<NavigationService>();
    final service = MockNavigationService();
    locator.registerSingleton<NavigationService>(service);
    return service;
    }
  2. Test case
    setUp(() {
    viewModel = CustomerConfirmDetailsViewModel();
    });
    test('Test navigateToDashboard():', () async {
    // Arrange
    final navService = getAndRegisterNavigationService();
    when(navService.popUntil(ModalRoute.withName(Routes.dashboardAgentView)))
        .thenAnswer((realInvocation) {});
    // Act
    viewModel.navigateToDashboard();
    // Assert
    verify(navService.popUntil(ModalRoute.withName(Routes.dashboardAgentView)));
    });
  3. Error: No matching calls. All calls: MockNavigationService.popUntil(Closure: (Route) => bool, {id: null}) (If you called verify(...).called(0);, please instead use verifyNever(...);.)

Expected behavior

I would like to be able to test when popUntil(), pushNamedAndRemoveUntil() and locator().back().

Screenshots

No response

Additional Context

No response

GameOnAnil commented 8 months ago

@ferrarafer @FilledStacks Could you please look into this issue.