I have this piece of code mocking a response:
(isFirstSubmit is initialized to true)
when(
mockProfileRepository.submitProfile(
localNumber: localNumber,
profileContactInfo: fakeProfileContactInfo.copyWith(
email: modifiedEmail,
phone: modifiedPhone,
),
),
).thenAnswer((_) async {
if (isFirstSubmit) {
debugPrint('Saving profile first time');
isFirstSubmit = false;
throw OrderInProgressException();
} else {
debugPrint('Saving profile...');
return Future.value(true);
}
});
However the throw OrderInProgressException makes the test abort instead of being part of the equation...
So what I want (just to be clear) is to mock returning an OrderInProgressException (which the submitProfile method would) first time and a Future.value(true) the second time.
How can I mock a condition like this?