hasResponse function Null safety

Matcher hasResponse(
  1. int? statusCode,
  2. {dynamic body,
  3. Map<String, dynamic>? headers,
  4. bool failIfContainsUnmatchedHeader = false}

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.


var response = await client.request("/foo").get();
expect(response, hasResponse(200, body: ["a"], headers: {
  "x-version" : "1.0"

For details on failIfContainsUnmatchedHeader, see hasHeaders.


Matcher hasResponse(int? statusCode,
    {dynamic body,
    Map<String, dynamic>? headers,
    bool failIfContainsUnmatchedHeader = false}) {
  return HTTPResponseMatcher(
      headers != null
          ? HTTPHeaderMatcher(headers,
              shouldFailIfOthersPresent: failIfContainsUnmatchedHeader)
          : null,
      body != null ? HTTPBodyMatcher(body) : null);