gpt4 book ai didi

flutter 单元测试提交通过,因为 TypeMatcher 错误

转载 作者:行者123 更新时间:2023-12-05 04:38:41 29 4
gpt4 key购买 nike

我为我的方法创建了一个单元测试:

    test(
"should return remote data when the call to remote data source is successfull",
() async {
List<LanguageResponseModel> list = <LanguageResponseModel>[];

final Map<String, dynamic> jsonMap =
json.decode(fixture('languages.json'));

when(_client.query(any)).thenAnswer((_) async =>
QueryResult(data: jsonMap, source: QueryResultSource.cache));

//act
var t = await mackApi.getLanguages();

//assert
expect(t, isA<Success<List<LanguageResponseModel>>>);
});
});

但是我不能通过我的测试:

我遇到了这个错误:

Expected: <Closure: () => TypeMatcher<Success<List<LanguageResponseModel>>> from Function 'isA': static.>
Actual: _$Success<List<LanguageResponseModel>>:<ApiResult<List<LanguageResponseModel>>.success(data: [LanguageResponseModel(id: 83a3d134-dd6e-4c76-84d4-8ae97ba35ff6, slug: en-US, name: English, flagUrl: https://ir/Language/c9e92b49-94d9-401e-901b-8d195efd4fe1_0.svg, languageDirection: LTR), LanguageResponseModel(id: cc2001cb-93d1-472a-a52c-330e79e7df73, slug: fa-IR, name: ii, flagUrl: https:/Language/64333b37-2943-4213-bc4d-b243faf38bc8_0.jpg, languageDirection: LTR)])>

package:test_api expect
expect
package:flutter_test/src/widget_tester.dart:455
main.<fn>.<fn>
test/…/api/splash_remote_data_source_test.dart:63

t 返回 Success<List<LanguageResponseModel>>那么为什么我得到错误:

最佳答案

它在 isA 被实例化时起作用例如

expect(t, isA<Success<List<LanguageResponseModel>>>());

关于 flutter 单元测试提交通过,因为 TypeMatcher 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70551624/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com