[英]Flutter Dartz bloc test argument type not assignable issue
I am writing flutter test method using bloc_test and mockito library.我正在使用 bloc_test 和 mockito 库编写 flutter 测试方法。 I am getting below strange issue while mocking repository API call.
在调用 mocking 存储库 API 时,我遇到了奇怪的问题。 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: getPosts 方法结构:
@override
Future<Either<Failure, List<PostEntity>>> getPosts() async {
}
Basic blocTest method code:基本的 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>()));
});
You are not using it in the right way.您没有以正确的方式使用它。
dartz
package uses Right
or Left
classes to access the actual type. dartz
package 使用Right
或Left
类来访问实际类型。 Simply change the postEntityList
to Right(postEntityList)
只需将
postEntityList
更改为Right(postEntityList)
when(() => mockRepository.getPosts())
.thenAnswer((_) async => Right(postEntityList));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.