Add support for mock lists in verifyNoMoreInteractions and verifyZeroInteractions
- 主要语言
- Dart
- 星标
- 702
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
描述
I'm always frustrated when I have to use multiple verifyNoMoreInteractions and verifyZeroInteractions calls for different mocks in my tests. It would be more efficient and readable if these methods could accept a list of mocks.
I would like the verifyNoMoreInteractions and verifyZeroInteractions methods to support passing a list of mocks. This way, we can verify multiple mocks in a single call, making the test code cleaner and easier to maintain.
An alternative solution would be to create a custom helper function in my own test code to loop through the mocks and call verifyNoMoreInteractions or verifyZeroInteractions on each one. However, having this functionality built into the Mocktail package would be more convenient and beneficial for all users.
Here is an example of a test case where multiple verifyNoMoreInteractions and verifyZeroInteractions calls are used:
```
presenter = SomePresenter(
mockA,
mockB,
mockC,
mockD,
mockE,
);
test('Some test case', () {
when(() => mockA.getSomeData())
.thenReturn(fakeData);
presenter.doSomething();
verifyInOrder([
() => mockA.getSomeData(),
() => mockB.trackAction(),
() => mockC.updateView(any()),
]);
verifyNoMoreInteractions(mockA);
verifyNoMoreInteractions(mockB);
verifyNoMoreInteractions(mockC);
verifyZeroInteractions(mockD);
verifyZeroInteractions(mockE);
});
```
To avoid using multiple verifyNoMoreInteractions and verifyZeroInteractions, my suggestion is to add support for passing a list of mocks to these methods.
```
presenter = SomePresenter(
mockA,
mockB,
mockC,
mockD,
mockE,
);
test('Some test case', () {
when(() => mockA.getSomeData())
.thenReturn(fakeData);
presenter.doSomething();
verifyInOrder([
() => mockA.getSomeData(),
() => mockB.trackAction(),
() => mockC.updateView(any()),
]);
verifyNoMoreInteractions([mockA, mockB, mockC]);
verifyZeroInteractions([mockD, mockE]);
});
```
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。