stubJson method
void
stubJson(})
Stubs a JSON response — usually a successful one.
A statusCode outside 2xx becomes a failure, as it does in production
(Dio rejects it), built from the status and body like stubFailure.
Implementation
void stubJson(
HttpMethod method,
String endpoint,
Object? body, {
int statusCode = 200,
Map<String, List<String>>? headers,
}) {
if (statusCode < 200 || statusCode >= 300) {
stub(method, endpoint, left(failureForStatus(statusCode, body)));
return;
}
stub(
method,
endpoint,
right(
Response(
requestOptions: RequestOptions(path: endpoint),
statusCode: statusCode,
data: body,
headers: headers == null ? null : Headers.fromMap(headers),
),
),
);
}