felangel / felangel/mocktail

Less verbose Mock declarations

Ouverte
#185 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
question waiting for response
Langage dominant
Dart
Étoiles
702
Forks
88
Métriques de merge des PR
Aucune PR mergée en 30 j

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).

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.