felangel / felangel/mocktail

Confusing failure with nested mocks

Open
#204 6 comments 1 reaction 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

I meant to file this a few weeks ago, sorry.

```dart
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class One {
final Two two = Two();
}

class Two {
final String three = '';
}

class _MockOne extends Mock implements One {}

class _MockTwo extends Mock implements Two {}

void main() {
test('nested mocks', () {
final one = _MockOne();
final two = _MockTwo();
when(() => one.two).thenReturn(two);
when(() => one.two.three).thenReturn('three');
expect(one.two.three, 'three');
});
}
```

```
00:02 +0 -1: nested mocks [E]
type 'String' is not a subtype of type 'Two'
test/foo_test.dart 12:7 _MockOne.two
test/foo_test.dart 22:16 main.
```

That's a better error than I remember (I remember it being silent?) But it's still pretty confusing. Feel free to close.

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.