HttpTestingController class
Captures HTTP work for deterministic request assertions without networking. Matching alone does not complete a request; use flush/fail and then verify.
- Implemented types
Constructors
Properties
- 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(
) → Future< void> -
Stops accepting requests and releases transport resources.
override
-
createClient(
{String? baseUrl, Map< String, String> defaultHeaders = const {}, List<HttpInterceptor> interceptors = const [], Duration? timeout}) → HttpClient - Creates a borrowed client. The test owns this controller and must close it.
-
expectNone(
String url, {HttpMethod? method}) → void -
expectOne(
String url, {HttpMethod? method}) → PendingRequest - Matches one request by full URL (including query) and optional method.
-
expectOneWhere(
bool predicate(HttpRequest), {String description = 'matching request'}) → PendingRequest - Matches exactly one request without consuming candidates on failure.
-
match(
bool predicate(HttpRequest)) → List< PendingRequest> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
send(
HttpRequest request, CancellationToken token) → Future< HttpResponse> -
override
-
toString(
) → String -
A string representation of this object.
inherited
-
verify(
{bool ignoreCanceled = false}) → void - Throws if a request is unmatched or incomplete, optionally ignoring canceled work.
-
waitForOne(
String url, {HttpMethod? method, Duration timeout = const Duration(seconds: 5)}) → Future< PendingRequest> - Waits for middleware-delayed requests without sleeps or polling. Matching reserves the request; flush/fail it and verify after awaiting work.
-
waitForOneWhere(
bool predicate(HttpRequest), {Duration timeout = const Duration(seconds: 5), String description = 'matching request'}) → Future< PendingRequest> - Event-driven predicate matching with a bounded wait and diagnostic failure.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited