I created a unit test for my method:
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>>>);
});
});
But my test doesn't pass:
I got this error :
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
When Success<List<LanguageResponseModel>> is returned, then why do I get error?
it works when isA is instantiated for example
expect(t, isA<Success<List<LanguageResponseModel>>>());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With