Validates that a TestResponse has the specified status code, body and headers.
This matcher will validate the status code, body and headers of a TestResponse. See also expectResponse.
Example:
var response = await client.request("/foo").get();
// Expects that response has status code 200, its body is decoded to a list with a single string element "a",
// and has a header "x-version" whose value is "1.0".
expect(response, hasResponse(200, ["a"], headers: {
"x-version" : "1.0"
});
If the status code of the response does not match the expected status code in this matcher, the matcher will fail.
bodyMatcher
is used to evaluate the decoded value of an HTTP response body. Decoding occurs according to
HTTPCodecRepository. In doing so, this method will implicitly ensure that the HTTP response body was decoded
according to its Content-Type header.
If bodyMatcher
is a primitive type (Map
, List
, String
, etc.), it will be wrapped in an equals
matcher. Otherwise,
it will use the behavior of the matcher specified.
When matching headers, header keys are evaluated case-insensitively. By default, only the key-value pairs specified by this method
are evaluated - if the response contains more headers than headers
, the additional response headers do not impact matching. Set failIfContainsUnmatchedHeader
to true to expect the exact set of headers.
The values for headers
must be String
, DateTime
, num
, or a Matcher
that compares to one of these types.
Source
Matcher hasResponse(int statusCode, dynamic bodyMatcher, {Map<String, dynamic> headers: null, bool failIfContainsUnmatchedHeader: false}) { return new HTTPResponseMatcher( statusCode, (headers != null ? new HTTPHeaderMatcher(headers, failIfContainsUnmatchedHeader) : null), (bodyMatcher != null ? new HTTPBodyMatcher(bodyMatcher) : null)); }