Skip to content

Commit

Permalink
feat(mocktail): improve verifyNoMoreInteractions failure message (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Mar 1, 2022
1 parent 70e915f commit 447575a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/mocktail/lib/src/_real_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RealCall {

@override
String toString() {
var verifiedText = verified ? '[VERIFIED] ' : '';
final verifiedText = verified ? '[VERIFIED] ' : '';
return '$verifiedText$mock.${invocation.toPrettyString()}';
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/mocktail/lib/src/mocktail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ void verifyNoMoreInteractions(dynamic mock) {
if (mock is Mock) {
final unverified = mock._realCalls.where((inv) => !inv.verified).toList();
if (unverified.isNotEmpty) {
fail('No more calls expected, but following found: ${unverified.join()}');
fail(
'''No more calls expected, but following found: ${unverified.join(', ')}\nDid you forget to call verify?\nExample: verify(() => cat.meow()).called(1);''',
);
}
} else {
_throwMockArgumentError('verifyNoMoreInteractions', mock);
Expand Down
19 changes: 14 additions & 5 deletions packages/mocktail/test/mockito_compat/verify_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,22 @@ void main() {
verifyNoMoreInteractions(mock);
});

test('any unverified touch fails', () {
test('any unverified touch fails (single invocation)', () {
mock.methodWithoutArgs();
expectFail(
'No more calls expected, but following found: '
'_MockedClass.methodWithoutArgs()', () {
verifyNoMoreInteractions(mock);
});
'''No more calls expected, but following found: _MockedClass.methodWithoutArgs()\nDid you forget to call verify?\nExample: verify(() => cat.meow()).called(1);''',
() => verifyNoMoreInteractions(mock),
);
});

test('any unverified touch fails (multiple invocations)', () {
mock
..methodWithoutArgs()
..methodWithOptionalArg();
expectFail(
'''No more calls expected, but following found: _MockedClass.methodWithoutArgs(), _MockedClass.methodWithOptionalArg(null)\nDid you forget to call verify?\nExample: verify(() => cat.meow()).called(1);''',
() => verifyNoMoreInteractions(mock),
);
});

test('verified touch passes', () {
Expand Down

0 comments on commit 447575a

Please sign in to comment.