flutter unit test filed pass because TypeMatcher error

Viewed 90

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 I cant pass my test:

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

t is return Success<List<LanguageResponseModel>> then Why I got error:

1 Answers

it works when isA is instantiated for example

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

Related