Skip to content

Expose a way to register default responses #254

Open
@timcreatedit

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions