felangel / felangel/mocktail

Confusing failure with nested mocks

未关闭
#204 6 条评论 1 个 reaction 已指派 1 人 已被 @felangel 认领 在 GitHub 查看
enhancement
主要语言
Dart
星标
702
派生
88
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。