felangel / felangel/mocktail

Less verbose Mock declarations

Open
#185 3 comments 0 reactions 0 assignees View on GitHub
question waiting for response
Dominant language
Dart
Stars
702
Forks
88
PR merge metrics
No merged PRs in 30d

Description

**Problem**
Currently defining a Mock looks like this:

```dart
class _MockDog extends Mock implements Dog {}
final Dog mockDog = _MockDog();
```

**Solution I would like**
I would like to have a one-line syntax alternative (or completely remove the old syntax):

```dart
final Dog mockDog = Mock();
```

The advantages are:
- Reduces the chances of creating a public Mock being shared, which leads to non self contained test files.
- Reduces file pollution, sometimes a test file can have multiple mocks and the class definitions of such pollutes the readability of the file.
- Somewhat forces developers that want to have any directly implemented
overridden fields or methods in a Mock to use a Fake. As detailed by the documentation (["A class which `extends Mock` should not have any directly implemented overridden fields or methods"](https://github.com/felangel/mocktail/blob/39d40c653819d09385af8955ef5d7259c58c9a58/packages/mocktail/lib/src/mocktail.dart#L79) ).

**Additional notes**
I'm willing to work on a pull request for this change if there is an agreement on the new syntax. As far as I am concerned having something exactly like the proposed solution would lead to a breaking change (depends on Dart's current and future capabilities). I'm opened to read about solutions that will avoid introducing a breaking change with the new syntax. I believe that a breaking change can be justified since the new syntax has many advantages and solves a couple of problems (as outlined in Additional Context).

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.