Reputation: 21
I use this library fpdart with Bloc for State Management. From fpDart I'm just using Either
to manage errors.
But now, when I'm doing my unit test for the Bloc I call a funcion that looks like this
Future<Either<Failure, List<Anime>>> getPopularAnime();
When I run this test:
group('⭐️ When [Started] is added. ', () {
Failure failure = Failure.badRequest();
final failureEither = Either<Failure, List<Anime>>.left(failure);
blocTest('emits [Loading,Error]',
build: () => landingBloc,
setUp: () {
when(animeRepository.getPopularAnime())
.thenAnswer((_) async => failureEither);
},
act: (bloc) => bloc.add(const LandingEvent.started()),
expect: () => [
const LandingState.loading(),
LandingState.error(failure),
]);
});
The animeRepository
that is in the code is a Mock generated by @GenerateNiceMocks([MockSpec<AnimeRepository>()])
Mockito says this
MissingDummyValueError: Either<Failure, List<Anime>> This means Mockito was not smart enough to generate a dummy value of type 'Either<Failure, List<Anime>>'. Please consider using either 'provideDummy' or 'provideDummyBuilder' functions to give Mockito a proper dummy value.
I expect when the bloc calls animeRepository.getPopularAnime() it returns Either<Failure, List<Anime>> because the bloc emits error in case of Left or emits success in case of right.
Upvotes: 2
Views: 439