-
Notifications
You must be signed in to change notification settings - Fork 163
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
"type 'Null' is not a subtype of type" on getter #608
Comments
Questions like this are best asked on a user forum like StackOverflow, with more eyes to look at the question. |
Yep, it seems we don't override getters with non-nullable return type, but we have to. Thanks for reporting. I plan to re-work the codegen for Dart3 support significantly, I think this bug will be fixed too. |
The rewrite didn't fly, so I guess we just have to do the overrides. |
Okay, thanks for your reply, good luck 😄 |
Actually I can't reproduce it. And the line that does the getter override is there since 2020. So, your generated code does indeed look wrong, but I don't understand how that could happen.
|
@AdrienAudouard ping, I can't fix it if I can't reproduce it :) |
This should be in the FAQ, I guess. You must declare variables holding mock objects to have late IAppLocalization mockAppLocalization; MUST be late MockIAppLocalization mockAppLocalization; |
Oh, sorry, my bad. While what I said is correct and you still have to declare your mocks to have Mock types (since that's static type that matters while checking if method arguments have correct type), in your case the error indeed comes from something else. There gotta be a generated override for Thanks for the reproduction. I'll take a look a bit later. |
Sure no problem. |
The problem with your code is |
Thank you for you insights. So basically generated code cannot be mocked. Is this an intended behavior for mockito or is it a feature that should be worked on? Also, can you elaborate on what you mean about "for real"? Do you mean running the test in an emulated environment such as an integration test? |
No, we can mock generated code, though there are also possible issues, since we have to be sure other generators run before mockito, and I think there is no generic way to ensure this. Actually this might be the cause here too, I thought the problem is the "magic" import, but maybe mockito generator just runs before flutter_gen? By "magic" import I mean that this By "for real" I mean when you run the test with |
Hello,
I'm trying to generate a mock for a class witch contains a getter, the source code of the class is:
Then I generate a mock of the class with mockito and with the following code:
When I run the tests I have the following error:
type 'Null' is not a subtype of type 'AppLocalizations'
, it look like in the generated code, the mock code of the getter is not generated.Can you help me please ? 🙏
The generated code:
The text was updated successfully, but these errors were encountered: