felangel / felangel/mocktail

Expose a way to register default responses

Open
#254 6 comments 2 reactions 1 assignee Claimed by @felangel View on GitHub
enhancement
Dominant language
Dart
Stars
702
Forks
88
PR merge metrics
No merged PRs in 30d

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

```dart
registerDefaultAnswer>((invocation) => Future.value());

// or

registerDefaultAnswer>((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 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**
- #233 (The recommended solution forces global mocks, which is often not desirable)
- #77
- #45

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.