-
Notifications
You must be signed in to change notification settings - Fork 166
@GenerateMocks does not generate correct stub for generic Future return Types #339
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
Comments
Same issue :( |
Trick: edit |
Maybe worth checking this issue out: Mocktail-Type-Safety. @srawlins He could solve this without any code generation. Sure it`s a breaking change but maybe its worth checking out for Mockito. |
Mocktail uses strings for mocking, in which case you lose all type safety, typo protection, static analysis, etc. We will not be moving in that direction. |
Sorry to contradict. The issue I linked was opened by me because I saw the same issues with Mocktail. It was lacking type safety but works without code generation. Felix found a solution based on lambdas to have type safety without code generation and working with null safety. He also proposed merging mockito into mocktail: #347 |
I also have a lot of |
@MaxAuer sorry I got my projects mixed up. |
@kuhnroyal can you elaborate? analysis_options.yaml does not affect compilation. |
@srawlins You are correct. What I meant to say is, that with analyzer:
language:
strict-inference: true
strict-raw-types: true
strong-mode:
implicit-dynamic: false
implicit-casts: false I know that I can exclude the generated files from analysis but it would be nice if the generated code conforms to these setting as it will then also conform to less strict settings. This would make it easier to add to projects. |
Thanks @kuhnroyal . That sounds like a separate issue from this issue. I can take a look if you file a separate issue, and include the new static errors you are seeing. |
A fix for this issue is available now with Mockito 5.0.9, "fallback generators". Please see the new section in the NULL_SAFETY_README: https://github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md#fallback-generators |
@srawlins Correct me if I'm wrong here, but since we don't care about actual results of Future objects and fallback generators serve only to make generated code null-safe, couldn't Mockito just return In a similar way methods that return generic streams are currently mocked. The difference here is that instead of a stream that never emits we just want a future that never completes. |
Hey,
I tried to generate a Mock for the following Function:
Several classes are extending
Base
.flutter pub run build_runner build
does output the following stub:I then use the following
when
in my test to stub the functionWhich gives the following error
type 'Future<Null>' is not a subtype of type 'Future<Note>' in type cast
. This does make sense asFuture.value(null)
can not be parsed toFuture<T>
which is not nullable.The correct behavior should be a value that can be parsed to
Future<T>
.The text was updated successfully, but these errors were encountered: