From e7a9cbe3be1ed11689124dd90fbaa5688aaead0e Mon Sep 17 00:00:00 2001 From: Naron <72578270+naronchen@users.noreply.github.com> Date: Sun, 2 Feb 2025 09:33:16 -0500 Subject: [PATCH] test(transform): add test case for issue 5853 on response type to 'json' (#5901) * test(transform): add test case for issue 5853 on response type to 'json' * test(transform): formatted second argument --------- Co-authored-by: Jay --- test/specs/transform.spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/specs/transform.spec.js b/test/specs/transform.spec.js index 4743be7..9ce7499 100644 --- a/test/specs/transform.spec.js +++ b/test/specs/transform.spec.js @@ -197,4 +197,31 @@ describe('transform', function () { done(); }); }); + + it('should return response.data as parsed JSON object when responseType is json', function (done) { + const instance = axios.create({ + baseURL: '/api', + transformResponse: [function (data) { + return data; + }], + responseType: 'json', + }); + + instance.get("my/endpoint", { responseType: 'json' }) + .then(response => { + expect(typeof response).toBe('object'); + done(); + }) + .catch(err => { + done(err); + }); + + getAjaxRequest().then(function (request){ + request.respondWith({ + status: 200, + responseText: '{"key1": "value1"}' + }); + }); + }); + });