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

'Null' is not a subtype of type 'Future<bool>' #742

Closed
avdhootu27 opened this issue Apr 6, 2024 · 3 comments
Closed

'Null' is not a subtype of type 'Future<bool>' #742

avdhootu27 opened this issue Apr 6, 2024 · 3 comments

Comments

@avdhootu27
Copy link

I am trying to mock a static method from the class MyDatabase which returns Future. So I created MockMyDatabaseWrapper as:

class MyDatabaseWrapper {
  Future<bool> insertFolder(Folder folder) async => await MyDatabase.insertFolder(folder);
}

class MockMyDatabaseWrapper extends Mock implements MyDatabaseWrapper {}

and in test I am mocking it as:

MockMyDatabaseWrapper mockMyDatabaseWrapper = MockMyDatabaseWrapper();
Folder testFolder = Folder(title: testFolderTitle);
when(await mockMyDatabaseWrapper.insertFolder(testFolder)).thenReturn(true);

but at line when(await mockMyDatabaseWrapper.insertFolder(testFolder)).thenReturn(true); I am getting an error:
The following _TypeError was thrown running a test: type 'Null' is not a subtype of type 'Future<bool>'

Can anyone please tell me what I am doing wrong here?

@avdhootu27
Copy link
Author

And one more thing, I am not able to use 'any' as parameter for insertFolder while mocking

@srawlins
Copy link
Member

srawlins commented Apr 7, 2024

So I created MockMyDatabaseWrapper as:

Definitely don't do that.

Please read in the README how to set up mocks.

@srawlins srawlins closed this as completed Apr 7, 2024
@avdhootu27
Copy link
Author

Thanks for this, but how to mock static methods?

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