Description
Is your feature request related to a problem? Please describe.
In large projects, it is often cumbersome to have to stub APIs over and over again, especially if you only want to verify
when they were called.
Describe the solution you'd like
It would be nice to be able to register default responses for certain return types, either per mock, or (even more useful), globally.
Right now, null
is returned from every stub by default. It would be nice to be able to do something like
registerDefaultAnswer<Future<void>>((invocation) => Future.value());
// or
registerDefaultAnswer<Future<void>>((invocation) => Future.value(), forMock: myMock);
Describe alternatives you've considered
Right now, methods that return void
don't need to actively be stubbed, since null
is returned by default. It is a bit inconsistent that the same doesn't apply to Future<void> Function(...)
, this Feature would allow for setting this up in a flutter_test_config.dart
file for example.
Since the _defaultResponses
mechanism is private, this can't really be implemented in another package like package:mocktailx
Additional context
- Mock with default stub implementation feature #233 (The recommended solution forces global mocks, which is often not desirable)
- Default, common use stubs #77
- Throws type 'Null' is not a subtype of type 'Future<void>' #45