hasHeaders function Null safety
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.
Implementation
Matcher hasHeaders(Map<String, dynamic> headerMatcher,
{bool failIfContainsUnmatchedHeader = false}) =>
HTTPResponseMatcher(
null,
HTTPHeaderMatcher(headerMatcher,
shouldFailIfOthersPresent: failIfContainsUnmatchedHeader),
null);