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

Mocking the (AutoDispose)FamilyNotifier with code generation incorrect #694

Open
5hirish opened this issue Sep 18, 2023 · 1 comment
Open

Comments

@5hirish
Copy link

5hirish commented Sep 18, 2023

On trying to mock a Riverpod StateNotifierProvider of (AutoDispose)FamilyNotifier -

@Riverpod(keepAlive: true)
class ProjectDirectoryPath extends _$ProjectDirectoryPath {
  @override
  String? build() {
    return null;
  }
}

Mockito code generation fails to generate the appropriate mock for it -

@GenerateNiceMocks([
  MockSpec<ProjectDirectoryPath>(),
])
void main() {
   container = ProviderContainer(overrides: [
        projectDirectoryPathProvider
            .overrideWith(() => mockProjectDirectoryPath),
      ]);
}

Error -

NoSuchMethodError: Class 'MockProjectDirectoryPath' has no instance method '_setElement'.
Receiver: Instance of 'MockProjectDirectoryPath'
Tried calling: _setElement(Instance of 'NotifierProviderElement<ProjectDirectoryPath, String?>')

How can I generate the appropriate mock using the code generation of mockito?
This issue is explored here in depth - rrousselGit/riverpod#2373

@andersjoh
Copy link

We are seeing the same issue, will add more information. @5hirish did you find a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants