Closed dfdgsdfg closed 3 months ago
If you want to have defaults then I recommend creating a Fake:
import 'package:mocktail/mocktail.dart';
class Cat {
Future<String> meow() async => 'meow';
}
class FakeCat extends Fake implements Cat {
@override
Future<String> meow() async => 'default meow';
}
void main() async {
final cat = FakeCat();
print(await cat.meow()); // default meow
}
Hope that helps! Closing for now đź‘Ť
Hi. From what I can tell, it is not possible to later override the behavior of a Fake with when
. I'm wondering if I could define a Fake/Mock class with default behavior, then override some of that only where necessary. For example, a repo that returns empty data unless overriden.
Hi. From what I can tell, it is not possible to later override the behavior of a Fake with
when
. I'm wondering if I could define a Fake/Mock class with default behavior, then override some of that only where necessary. For example, a repo that returns empty data unless overriden.
If you really want to do that then you can add the stubs in the mock class’s constructor body or create a helper function that constructs the mock instance and stubs the default methods.
How about add default stub when define the mock class?
Is this possible by any chance?
Work around