felangel / felangel/mocktail

Add support for mock lists in verifyNoMoreInteractions and verifyZeroInteractions

Open
#245 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Dart
Stars
702
Forks
88
PR merge metrics
No merged PRs in 30d

Description

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]);
});
```

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.