Improve error when non-mock method is called in when().
We've seen many users confused about mocking extension methods. There is an FAQ entry, but improving the error message is important as well.
PiperOrigin-RevId: 322132516
diff --git a/lib/src/mock.dart b/lib/src/mock.dart
index 793f8f6..fe7d47c 100644
--- a/lib/src/mock.dart
+++ b/lib/src/mock.dart
@@ -439,8 +439,8 @@
void _completeWhen(Answering<T> answer) {
if (_whenCall == null) {
throw StateError(
- 'Mock method was not called within `when()`. Was a real method '
- 'called?');
+ 'No method stub was called from within `when()`. Was a real method '
+ 'called, or perhaps an extension method?');
}
_whenCall._setExpected<T>(answer);
_whenCall = null;