testing library
This library contains testing classes for the HTTP library.
The MockClient class is a drop-in replacement for http.Client
that
allows test code to set up a local request handler in order to fake a server
that responds to HTTP requests:
import 'dart:convert';
import 'package:cancellation_token_http/testing.dart';
var client = MockClient((request) async {
if (request.url.path != "/data.json") {
return Response("", 404);
}
return Response(
json.encode({
'numbers': [1, 4, 15, 19, 214]
}),
200,
headers: {'content-type': 'application/json'});
});
Classes
- MockClient
- A mock HTTP client designed for use when testing code that uses BaseClient.
Typedefs
-
MockClientHandler
= Future<
Response> Function(Request request) - A handler function that receives Requests and sends Responses.
-
MockClientStreamHandler
= Future<
StreamedResponse> Function(BaseRequest request, ByteStream bodyStream) - A handler function that receives StreamedRequests and sends StreamedResponses.