Skip to content

How to generate mock for Stream? #379

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

Closed
Albert221 opened this issue Apr 8, 2021 · 2 comments
Closed

How to generate mock for Stream? #379

Albert221 opened this issue Apr 8, 2021 · 2 comments

Comments

@Albert221
Copy link

Code:

@GenerateMocks([], customMocks: [
  MockSpec<Stream<Uri?>>(as: #MockNullableUriStream),
])
class _Nothing {}

Output:

[SEVERE] mockito:mockBuilder on test/mocks.dart:

Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock class which implements 'Stream' for the following reasons:
    The method 'Stream.map' features a non-nullable unknown return type, and cannot be stubbed.
    The method 'Stream.reduce' features a non-nullable unknown return type, and cannot be stubbed.
    The method 'Stream.fold' features a non-nullable unknown return type, and cannot be stubbed.
    The method 'Stream.firstWhere' features a non-nullable unknown return type, and cannot be stubbed.
    The method 'Stream.lastWhere' features a non-nullable unknown return type, and cannot be stubbed.
    The method 'Stream.singleWhere' features a non-nullable unknown return type, and cannot be stubbed.

mockito 5.0.0 - build_runner 1.11.5 - Flutter 2.0.3

@srawlins srawlins changed the title How to generate mock for stream of nullables? How to generate mock for Stream? Apr 8, 2021
@srawlins
Copy link
Member

srawlins commented Apr 8, 2021

It is not possible yet. #342 is one proposed solution.

@srawlins
Copy link
Member

This is now possible (though not very fun) with Mockito 5.0.9. Please see the new section in the NULL_SAFETY_README:

https://github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md#fallback-generators

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