async_notifier_example_riverpod icon indicating copy to clipboard operation
async_notifier_example_riverpod copied to clipboard

Used on a non-mockito object

Open gaganyadav80 opened this issue 3 years ago • 1 comments

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>

gaganyadav80 avatar Dec 27 '22 11:12 gaganyadav80

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.

joakimunge avatar Aug 30 '23 09:08 joakimunge