hasHeaders function Null safety

Matcher hasHeaders(
  1. Map<String, dynamic> headerMatcher,
  2. {bool failIfContainsUnmatchedHeader = false}

Validates that TestResponse has headers that match headerMatcher.

Each key in headerMatcher is case-insensitively compared to the headers in the actual response, the matcher for the key is then compared to the header value.

By default, if a response contains a header name not in headerMatcher, it is ignored and any value will be acceptable. This is the same behavior as if using partial.

  var response = await client.request("/foo").get();
  expect(response, hasHeaders({
    "x-timestamp": isBefore(DateTime.now())

You may pass failIfContainsUnmatchedHeader as true to force evaluate every header in the response - but recall that many requests contain headers that do not need to be tested or may change depending on the environment.


Matcher hasHeaders(Map<String, dynamic> headerMatcher,
        {bool failIfContainsUnmatchedHeader = false}) =>
            shouldFailIfOthersPresent: failIfContainsUnmatchedHeader),