jsonResponse function

Response jsonResponse(
  1. Object? body, {
  2. int status = 200,
  3. Map<String, String>? headers,
})

A JSON response, encoded with the header a client will look for.

Hand-writing http.Response(jsonEncode(body), 200, headers: {...}) in every test is how the content-type gets forgotten — and a client that decodes on that header then fails in a way that points at the parser rather than at the fixture. This is the shape a mocked REST answer almost always takes, so it belongs here rather than in each app's test helpers.

bifrostMockResponder = (request) async => jsonResponse([row, row]);
bifrostMockResponder = (request) async =>
    jsonResponse({'message': 'denied'}, status: 403);

Implementation

http.Response jsonResponse(
  Object? body, {
  int status = 200,
  Map<String, String>? headers,
}) =>
    http.Response(
      jsonEncode(body),
      status,
      headers: {'content-type': 'application/json', ...?headers},
    );