MockHttpClientAdapter class
HttpClientAdapter implementation for test isolation.
Pass a handler callback to control responses without a real network
connection. Import via package:fbae_core/fbae_core_testing.dart.
Usage:
import 'package:fbae_core/fbae_core_testing.dart';
final adapter = MockHttpClientAdapter((options) async {
return ResponseBody.fromString(
'{"id":1}',
200,
headers: {Headers.contentTypeHeader: [Headers.jsonContentType]},
);
});
dio.httpClientAdapter = adapter;
Constructors
-
MockHttpClientAdapter(Future<
ResponseBody> handler(RequestOptions options))
Properties
-
handler
→ Future<
ResponseBody> Function(RequestOptions options) -
Called for every request. Return a
ResponseBodyto simulate any HTTP response, including errors (e.g.statusCode: 401).final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
{bool force = false}) → void - Close the current adapter and its inner clients or requests.
-
fetch(
RequestOptions options, Stream< Uint8List> ? requestStream, Future<void> ? cancelFuture) → Future<ResponseBody> - Implement this method to make real HTTP requests.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited