bizz84 / async_notifier_example_riverpod

AsyncNotifier example with Riverpod
https://codewithandrea.com/
MIT License
29 stars 8 forks source link

Used on a non-mockito object #3

Open gaganyadav80 opened 1 year ago

gaganyadav80 commented 1 year ago
class Listener<T> extends Mock {
  void call(T? previous, T next);
}

void main() {
  ProviderContainer makeProviderContainer() {
    final ProviderContainer container = ProviderContainer(
      overrides: <Override>[
        secureStorageServiceProvider.overrideWithValue(mockSecureStorage),
        activeSessionsRepositoryProvider.overrideWithValue(mockActiveSessionsRepository),
      ],
    );
    addTearDown(container.dispose);
    return container;
  }

  test(
    'Fetch all active sessions',
    () async {
      final ProviderContainer container = makeProviderContainer();
      final Listener<ActiveSessionsState> listener = Listener<ActiveSessionsState>();

      container.listen(
        activeSessionsNotifer,
        listener,
        fireImmediately: true,
      );

      verify(() => listener(const ActiveSessionsInitialState(), const ActiveSessionsLoadingState()));
    },
  );
}

The verify call is giving me the below error and I believe it is because the use of Listener class.

Used on a non-mockito object
package:test_api                                                                                   fail
_makeVerify.<fn>
main.<fn>
joakimunge commented 1 year ago

Ran into this today as well @bizz84 . Any idea what is wrong with the tests here?

Edit: In my case it was because I was using Mockito rather than Mocktail.