Sdk

Testing

Testing repositories with MockDio / Mockito.

Testing

Repositories are easy to test because HTTP is abstracted.

Example with MockDio + a repository using SearchFactory<T>:

when(mockDio.post('/items/search')).thenAnswer(
  (_) async => Response(
    requestOptions: RequestOptions(path: '/items/search'),
    statusCode: 200,
    data: {'data': [{'id': 1, 'name': 'Test'}]},
  ),
);

final res = await ItemRepository(mockDio).search();

expect(res.statusCode, 200);
expect(res.data?.first.id, 1);