mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
ef3711d1b3
* feat: implement prettier and fix all issues * fix: failing tests * fix: implement feedback from codel, ai etc * chore: dont throw in trim function Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: incorrect fix --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import defaults from '../../../lib/defaults/index.js';
|
|
import transformData from '../../../lib/core/transformData.js';
|
|
import assert from 'assert';
|
|
|
|
describe('transformResponse', function () {
|
|
describe('200 request', function () {
|
|
it('parses json', function () {
|
|
const data = '{"message": "hello, world"}';
|
|
const result = transformData.call(
|
|
{
|
|
data,
|
|
response: {
|
|
headers: { 'content-type': 'application/json' },
|
|
status: 200,
|
|
},
|
|
},
|
|
defaults.transformResponse
|
|
);
|
|
assert.strictEqual(result.message, 'hello, world');
|
|
});
|
|
it('ignores XML', function () {
|
|
const data = '<message>hello, world</message>';
|
|
const result = transformData.call(
|
|
{
|
|
data,
|
|
response: {
|
|
headers: { 'content-type': 'text/xml' },
|
|
status: 200,
|
|
},
|
|
},
|
|
defaults.transformResponse
|
|
);
|
|
assert.strictEqual(result, data);
|
|
});
|
|
});
|
|
describe('204 request', function () {
|
|
it('does not parse the empty string', function () {
|
|
const data = '';
|
|
const result = transformData.call(
|
|
{
|
|
data,
|
|
response: {
|
|
headers: { 'content-type': undefined },
|
|
status: 204,
|
|
},
|
|
},
|
|
defaults.transformResponse
|
|
);
|
|
assert.strictEqual(result, '');
|
|
});
|
|
it('does not parse undefined', function () {
|
|
const data = undefined;
|
|
const result = transformData.call(
|
|
{
|
|
data,
|
|
response: {
|
|
headers: { 'content-type': undefined },
|
|
status: 200,
|
|
},
|
|
},
|
|
defaults.transformResponse
|
|
);
|
|
assert.strictEqual(result, data);
|
|
});
|
|
});
|
|
});
|