Here's how I fetch data from an endpoint:
@override
Future<Team> getPoints({required int id}) async {
try {
Response pointsResponse = await dio.get(
"points/$id/",
);
return Points.fromJson(pointsResponse.data);
} on DioError catch (dioError) {
throw ServerException(dioError.message);
}
}
Now as a part of my test, I want to test that calling getPoints(id: 12) would make a get call on dio and hit this endpoint: points/12/.
Sample test:
test(
"should return Points for a valid id",
() async {
when(mockDioAdapter.fetch(any, any, any)).thenAnswer(
(_) async => successfulRequestResponseJson,
);
Points points = await pointsRemoteDataSource.getPoints(id: 12);
// Want to assert something like:
// verify(dio.request.path, "/points/12");
},
);
Aucun commentaire:
Enregistrer un commentaire