flutter-tdd-clean-architecture-course
flutter-tdd-clean-architecture-course copied to clipboard
type 'Null' is not a subtype of type 'Future<Either<Failure, LocalUser>>'
I just changed a few things here and there and I encountered this weird problem and solution.
Full details here :- https://stackoverflow.com/questions/67443531/flutter-using-async-in-testing-produces-an-error-but-using-async-made-it-work
If you're using Flutter 2:
- Upgrade dartz to ns prerelease: 0.10.0-nullsafety.2
- And replace mockito with mocktail.
I found the solution, which is suprising easy and I'm stupid. I havent tried using mocktail yet but using mockito is still perfectly fine as well. I just didnt generate Mock classes as stated in the mockito docs to support null safety. I also explained in the stackoverflow posts
This problem is about the Mockito version (not null safety). Upgrade your version to ^5.0.0. More about Mockito and null safety you can read here (Mockito - NULL_SAFETY_README)
You can try mocktail as well, the example below.
when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber))
.thenAnswer((_) async => Right(tNumberTrivia));
final result = await usecase.execute(number: tNumber);
expect(result, equal(Right(tNumberTrivia)));
verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber));
verifyNoMoreInteractions(mockNumberTriviaRepository);
The problem related with null-safety. I faced the same problem and later on I fixed. You can check it