-
Notifications
You must be signed in to change notification settings - Fork 164
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
Mocks created with GenerateMocks do not throw on missing stub when the function returns a Future<void> #581
Comments
I've just noticed that this also happens if the function returns
If this really the correct behaviour then I think there is a bug in the documentation here: Line 147 in 094d07c
This makes it sound like the call should throw, because the test never used |
Yes it is intentional for functions that return both |
What's the rationale behind this behaviour? That |
Yeah that's the general idea. We're implementing the idea that it's a pain to make people spell out in tests, "when this void-returning method is called with whatever, it should return, big surprise, nothing." You're right that there are multiple behaviors such a call could do, like throw anything. 🤷 It's just an implementation choice. |
I think it would be more consistent to make function that return I spotted this problem when the code I was testing was calling a function returning |
I'll save my comments on the fact that this is a huge headache to run into for anyone new to this package with the README being in direct contradiction with the actual behavior, and just say this: You can work around this by specifying a return type |
A call on a function with the signature
Future<void> returnsFutureVoid() => Future.value();
with no expected calls set up withwhen
will not cause a MissingStubError.I have read through the README, the FAQ and some of the test cases. From what I understand, this error should always be thrown for mocks generated with
GenerateMocks
. I couldn't find any documented problems with functions that return a future. I was not able to reproduce the issue for the mock in themockito_test.dart
file.I'll open a pull request with a new test case to demonstrate the issue. If this is a valid bug, I would appreciate any advice on how to fix it.
The text was updated successfully, but these errors were encountered: