1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] I don't know the value returned to me when testing bloc in Flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 17, 2024 às 10:53.

  1. Stack

    Stack Membro Participativo

    Im developing an app on Flutter. I want to test bloc using mockito but I don't know response. (status code:200 but response is a very big and dynamic model)

    I read the same example in every source, I don't understand. Please help me, Thank you.

    blocTest<DataBloc, DataState>(
    'emits [loading, data] when API call is successful',
    build: () {
    when(mockApiService.get(any)).thenAnswer(
    (_) async => http.Response('{"data": "sample data"}', 200),
    );
    return dataBloc;
    },
    act: (bloc) => bloc.add(FetchDataEvent()),
    expect: () => [
    DataState(loading: true), // İlk loading durumu
    DataState(data: '{"data": "sample data"}'), // Başarılı yanıt
    ],
    );

    Continue reading...

Compartilhe esta Página