簡體   English   中英

Flutter Dartz bloc 測試參數類型不可分配問題

[英]Flutter Dartz bloc test argument type not assignable issue

我正在使用 bloc_test 和 mockito 庫編寫 flutter 測試方法。 在調用 mocking 存儲庫 API 時,我遇到了奇怪的問題。 這可能是一個簡單的修復,但我從最近幾個小時開始嘗試它:(。

在此處輸入圖像描述

類似的代碼存在於其他公共存儲庫中,但在這里它不起作用。

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

getPosts 方法結構:

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

基本的 blocTest 方法代碼:

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

您沒有以正確的方式使用它。 dartz package 使用RightLeft類來訪問實際類型。 只需將postEntityList更改為Right(postEntityList)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM