Skip to content
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

Expose a way to register default responses #254

Open
timcreatedit opened this issue Jan 2, 2025 · 0 comments
Open

Expose a way to register default responses #254

timcreatedit opened this issue Jan 2, 2025 · 0 comments

Comments

@timcreatedit
Copy link

timcreatedit commented Jan 2, 2025

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

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

1 participant