hasResponse function
Matcher
hasResponse(})
Validates that TestResponse has matching statusCode
, body
, and headers
.
This method composes hasStatus, hasBody, and hasHeaders into a single matcher. See each of these individual method for behavior details.
If either body
or headers
is null or not provided, they will not be matched and
any value will be acceptable.
Example:
var response = await client.request("/foo").get();
expect(response, hasResponse(200, body: ["a"], headers: {
"x-version" : "1.0"
});
For details on failIfContainsUnmatchedHeader
, see hasHeaders.
Implementation
Matcher hasResponse(int? statusCode,
{dynamic body,
Map<String, dynamic>? headers,
bool failIfContainsUnmatchedHeader = false}) {
return HTTPResponseMatcher(
statusCode,
headers != null
? HTTPHeaderMatcher(headers,
shouldFailIfOthersPresent: failIfContainsUnmatchedHeader)
: null,
body != null ? HTTPBodyMatcher(body) : null);
}