TestResponse class

Response wrapper for testing assertions.

Provides convenient accessors for status, headers, and body.

Example:

final res = await client.get('/users');
expect(res.status, 200);
expect(res.json['name'], 'John');
Available extensions

Constructors

TestResponse(HttpClientResponse _raw)

Properties

body → Future<String>
Response body as string (fetched lazily).
no setter
bodyBytes → Future<List<int>>
Response body as bytes (fetched lazily).
no setter
contentType → String?
Content-Type header value.
no setter
cookieValues → Map<String, String>

Available on TestResponse, provided by the CookieTestingExtension extension

Gets all Set-Cookie headers as a map of name to value.
no setter
expect → ResponseExpect

Available on TestResponse, provided by the FluentAssertions extension

Returns a fluent assertion builder for this response.
no setter
hashCode → int
The hash code for this object.
no setterinherited
headers → HttpHeaders
Response headers.
no setter
isClientError → bool
Whether the response is a client error (4xx).
no setter
isOk → bool
Whether the response indicates success (2xx).
no setter
isRedirect → bool
Whether the response is a redirect (3xx).
no setter
isServerError → bool
Whether the response is a server error (5xx).
no setter
json → Future
Response body parsed as JSON (fetched lazily).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
status → int
HTTP status code.
no setter

Methods

getCookie(String name) → String?

Available on TestResponse, provided by the CookieTestingExtension extension

Gets a specific cookie value by name.
hasCookieNamed(String name) → bool

Available on TestResponse, provided by the CookieTestingExtension extension

Checks if a cookie exists.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited