【发布时间】:2020-03-03 04:00:32
【问题描述】:
我希望从返回类型Either<Exception, Object> 的方法中轻松提取值。
我正在做一些测试,但无法轻松测试我的方法的返回。
例如:
final Either<ServerException, TokenModel> result = await repository.getToken(...);
为了测试我能做到这一点
expect(result, equals(Right(tokenModelExpected))); // => OK
现在如何直接检索结果?
final TokenModel modelRetrieved = Left(result); ==> Not working..
我发现我必须这样投射:
final TokenModel modelRetrieved = (result as Left).value; ==> But I have some linter complain, that telling me that I shouldn't do as to cast on object...
我也想测试异常但它不起作用,例如:
expect(result, equals(Left(ServerException()))); // => KO
所以我尝试了这个
expect(Left(ServerException()), equals(Left(ServerException()))); // => KO as well, because it says that the instances are different.
【问题讨论】:
标签: unit-testing flutter dart either