If you make an incomplete mock, like calling when but forgetting to call thenReturn or thenAnswer, when you start a new mock, mocktail will break on that line, making you think that the issue is there, when it actually isn't, making it hard to track the error.
To Reproduce
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class _MockFoo extends Mock implements Foo {}
class Foo {
const Foo({
required Map<String, dynamic> data,
}) : _data = data;
final Map<String, dynamic> _data;
dynamic operator [](String key) => _data[key];
String sayHello() => 'Hello, ${_data['Name']}!';
}
void main() {
late Foo foo;
setUp(() {
foo = _MockFoo();
when(() => foo['Name']); // <- This is incomplete
});
test('say hello, says hello', () {
when(() => foo.sayHello()).thenReturn('Hello, Bond, James Bond!'); // <- Test will break here, but this mock is fine
expect(foo.sayHello(), 'Hello, Bond, James Bond!');
});
}
Expected behavior
I understand that it might be hard to break in the incomplete mock, but maybe the messaging could at least be improved, since in a big test file, tracking down this type of error can be quite challenging.
Describe the bug
If you make an incomplete mock, like calling
when
but forgetting to callthenReturn
orthenAnswer
, when you start a new mock, mocktail will break on that line, making you think that the issue is there, when it actually isn't, making it hard to track the error.To Reproduce
Expected behavior I understand that it might be hard to break in the incomplete mock, but maybe the messaging could at least be improved, since in a big test file, tracking down this type of error can be quite challenging.