Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter unit test failed because TypeMatcher error

Tags:

flutter

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?

like image 208
Cyrus the Great Avatar asked Nov 02 '25 17:11

Cyrus the Great


1 Answers

it works when isA is instantiated for example

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

like image 105
ahanor nosa Avatar answered Nov 05 '25 12:11

ahanor nosa