I’m testing my repository code that use Chopper, and am now getting the below errors, that isn’t in my code:
Null check operator used on a null value package:chopper/src/interceptor.dart 195:58 HttpLoggingInterceptor.onResponse package:chopper/src/base.dart 215:23 ChopperClient._interceptResponse package:chopper/src/base.dart 346:17 ChopperClient._processResponse package:chopper/src/base.dart 341:12
ChopperClient.send
I’ve created a static method that return my own chopper service as follows:
static MyChopperService create(String baseUrl, [http.Client? client]) {
return _$MyChopperService (
ChopperClient(
baseUrl: baseUrl,
client: client,
services: [_$MyChopperService ()],
interceptors: [
HttpLoggingInterceptor(),
CurlInterceptor(),
],
converter: const JsonConverter(),
),
);
}
In my unit tests I create the service as follows:
final MockClient mockClient = MockClient((req) async => Response('return data', 200));
final MyChopperService service = MyChopperService.create('baseUrl', client: mockClient);
... then I go ahead and use this calling my repository.
Any ideas what I’m doing wrong?
Based on what I can see, you have two options:
Response
in theMockClient
, also add aRequest
object that carries the Uri/Url. That is missing which seems to be something that theChopper
library haven’t guarded against.Edit: Meaning you could do something like this:
So change the method signature to instead have this:
and use this in the
ChopperClient
constructor:Then call it in your test like this: