assertJson method

TestResponse assertJson(
  1. Map<String, Object?> subset
)

Every key in subset must be present in the JSON body with an equal value.

Implementation

TestResponse assertJson(Map<String, Object?> subset) {
  final decoded = json;
  _check(decoded is Map, 'Response is not a JSON object: $body');
  final map = decoded as Map;
  for (final e in subset.entries) {
    _check(
      map.containsKey(e.key),
      'JSON key [${e.key}] expected ${jsonEncode(e.value)} but the key is missing. Body: $body',
    );
    _check(
      _deepEquals(map[e.key], e.value),
      'JSON key [${e.key}] expected ${jsonEncode(e.value)} but got ${jsonEncode(map[e.key])}',
    );
  }
  return this;
}