Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mocktail): improve verifyNoMoreInteractions failure message #118

Merged
merged 1 commit into from Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mocktail/lib/src/_real_call.dart
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
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
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