I'm trying to mock my Dio client with http-mock-adapter on put method and error method but I get this errors:
Exception: Assertion failed: "Could not find mocked route matching request for POST /onboard/answer { data: {"pageId":"1"},
Exception: DioError [DioErrorType.response]: {message: Some beautiful error!}
I found this issue https://githubmemory.com/repo/lomsa-dev/http-mock-adapter/issues/96?page=2 but I didn't solve my problem. Below is the code
main() {
final dio = Dio(BaseOptions());
final dioAdapter = DioAdapter(dio: dio);
dio.httpClientAdapter = dioAdapter;
final service = NetworkService(dio);
test("should return a DioError", () async {
const path = "/onboard/page-date/0/lastAnswerId";
final dioError = DioError(
error: {'message': 'Some beautiful error!'},
requestOptions: RequestOptions(path: path),
response: Response(
statusCode: 404,
requestOptions: RequestOptions(path: path),
),
type: DioErrorType.response,
);
dioAdapter.onGet(path, (server) {
server.throws(404, dioError);
});
final result = await service.getOnboardingAnswer("lastAnswerId");
expect(result, isA<OnboardModel>());
});
final answerModel = AnswerModel(pageId: "1");
test("should return 200", () async {
const path = "/onboard/answer";
dioAdapter.onPost(path, (server) {
server.reply(200, 200);
});
final result = await service.postOnboardingAnswer(answerModel);
expect(result, isA<int>());
});