简体   繁体   中英

Flutter Dartz bloc test argument type not assignable issue

I am writing flutter test method using bloc_test and mockito library. I am getting below strange issue while mocking repository API call. It might be a simple fix but I am trying it since last couple of hours:(.

在此处输入图像描述

Similar code is present in other public repositories but here its not working.

when(() => mockRepository.getPosts())
              .thenAnswer((_) async => Right(postEntityList));

getPosts method structure:

  @override
  Future<Either<Failure, List<PostEntity>>> getPosts() async {
  }

Basic blocTest method code:

group('whenListen', () {
    blocTest('verify posts bloc tests',
        build: () {
          when(() => mockRepository.getPosts())
              .thenAnswer((_) async => postEntityList);
          return postsBloc;
        },
        act: (PostsBloc postBloc) {
          postBloc.getAllPostsUseCase();
        },
        expect: () => (isA<PostsInitial>()));
  });

You are not using it in the right way. dartz package uses Right or Left classes to access the actual type. Simply change the postEntityList to Right(postEntityList)

when(() => mockRepository.getPosts())
              .thenAnswer((_) async => Right(postEntityList));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM