mardi 26 mai 2020

Error: List

I am working on an app using clean architecture principles. So, I made a repository

abstract class TrainerIdPlusInfoRepo {

 Future<Either<Failure,List<List>>> getTrainerIdPlusInfo();

 }

Then, I made a use case class.

  class GetTrainerAll extends UseCase<List, NoParams> {
  TrainerIdPlusInfoRepo trainerIdPlusInfoRepo;
  GetTrainerAll({ this.trainerIdPlusInfoRepo});
  @override
  Future <Either<Failure,List>> call(NoParams params) async{
  List trainerList =[];
  final listOfList = await trainerIdPlusInfoRepo.getTrainerIdPlusInfo();
  final result = listOfList.fold((failure)=> failure , (successData) {
  int length=  successData.length ;
    for(int i = 0 ; i < length; i++){
     trainerList.add(successData[i][1]);
    }
  return trainerList;
    } );
   return result;
    }

    }

Then I wrote a test for it.

    class MockTrainerIdPlusInfoRepo extends Mock implements TrainerIdPlusInfoRepo{}

    void main(){
    GetTrainerAll getTrainerAll ;
    MockTrainerIdPlusInfoRepo mockTrainerIdPlusInfoRepo; 

    setUp((){
    mockTrainerIdPlusInfoRepo = MockTrainerIdPlusInfoRepo();
    getTrainerAll= GetTrainerAll(trainerIdPlusInfoRepo: mockTrainerIdPlusInfoRepo,
    );

    });
    final tTrainer = Trainer(
    name: 'Test data',
    yearsOfExperience: 'Test data'

    );
    final tListOfList= [['Test data', tTrainer],['Test data', tTrainer]];
    final List<Trainer> tSuccessData = [tTrainer,tTrainer];

    group('getTrainerAll',(){

    test('should return a list of trainer if getTrainerInfoPlusId returns a List',

    () async{

  //arrange

      when(mockTrainerIdPlusInfoRepo.getTrainerIdPlusInfo())
          .thenAnswer((_) async=> Right(tListOfList) );
  // act


      final result = await getTrainerAll(NoParams());

  //assert
      expect(result.runtimeType, Right(tSuccessData));





    });

    });
    }

Result : type 'List' is not a subtype of type 'FutureOr>>'.

According to my logic, in the test, I declared that mockTrainerIdPlusInfoRepo.getTrainerIdPlusInfo() should return the Right side of either. Hence, when getAllTrainer() is called, then the result corresponding to the right value should be called. So, the test shall pass.

Please tell me where I went wrong.

Aucun commentaire:

Enregistrer un commentaire