mocktail
mocktail copied to clipboard
type 'Null' is not a subtype of type 'Future<Either<Failure, UnblockingEntity>>
Hi, The following error gets thrown and thenAnswer part never gets called: type 'Null' is not a subtype of type 'Future<Either<Failure, UnblockingEntity>>'
That's how I mock my use cases:
class MockUnblockOfferUseCase extends Mock implements UnblockOfferUseCase {}
class MockLogAnalyticsEventUseCase extends Mock
implements LogAnalyticsEventUseCase {}
That's how I stub their methods:
void arrangeUnblockOfferSuccess() {
when(() => logAnalyticsEventUseCase.call(
LogEventParams(event: AnalyticsEvents.unlockOffer, params: null)))
.thenAnswer((_) async => const Right(null));
when(() => unblockOfferUseCase.call(defaultOfferParams))
.thenAnswer((_) async => Right(UnblockingEntity(code: 'test')));
}
This is my test:
blocTest<ActivationBloc, ActivationState>(
'check that UnblockOfferUseCase gets called',
setUp: () {
arrangeUnblockOfferSuccess();
},
build: () => sut,
act: (bloc) =>
bloc.add(OfferUnblocked(offerId: defaultOfferParams.offerId)),
verify: (_) {
verify(() => unblockOfferUseCase.call(defaultOfferParams)).called(1);
});
This is the first use case:
class UnblockOfferUseCase extends UseCase<UnblockingEntity, OfferParams> {
final OfferRepository offerRepository;
UnblockOfferUseCase({required this.offerRepository});
@override
Future<Either<Failure, UnblockingEntity>> call(OfferParams params) async {
return await offerRepository.unblock(offerId: params.offerId);
}
}
class OfferParams {
final String offerId;
OfferParams({required this.offerId});
}
This is the second use case
class LogAnalyticsEventUseCase extends UseCase<void, LogEventParams> {
final FirebaseAnalyticsRepository firebaseAnalyticsRepository;
final CleverTapRepository cleverTapRepository;
LogAnalyticsEventUseCase({
required this.firebaseAnalyticsRepository,
required this.cleverTapRepository,
});
@override
Future<Either<Failure, void>> call(LogEventParams params) async {
firebaseAnalyticsRepository.logEvent(
event: params.event, params: params.params);
cleverTapRepository.logEvent(event: params.event, params: params.params);
return const Right(null);
}
}
class LogEventParams {
final String event;
final Map<String, dynamic>? params;
LogEventParams({required this.event, required this.params});
}
I've also tried the solutions from other similar issues but with no luck. @felangel , please have a look at this.