我为我的方法创建了一个单元测试:
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
当Success<List<LanguageResponseModel>>
返回时,为什么会出现错误?
1条答案
按热度按时间lnlaulya1#
例如,它在示例化伊萨时有效
expect(t, isA<Success<List<LanguageResponseModel>>>());