mirror of
https://github.com/axios/axios.git
synced 2026-04-13 02:51:56 +08:00
* Adding HTTP status code for transformResponse * refs #1214 * Fix wrong argument for tranformResponse * Fix test wrong argument for tranformData * Add test case for transformData * Add test case for transformData (reference headers case) Co-authored-by: Jay <jasonsaayman@gmail.com>
31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
var defaults = require('../../../lib/defaults');
|
|
var transformData = require('../../../lib/core/transformData');
|
|
var assert = require('assert');
|
|
|
|
describe('transformResponse', function () {
|
|
describe('200 request', function () {
|
|
it('parses json', function () {
|
|
var data = '{"message": "hello, world"}';
|
|
var result = transformData(data, {'content-type': 'application/json'}, 200, defaults.transformResponse);
|
|
assert.strictEqual(result.message, 'hello, world');
|
|
});
|
|
it('ignores XML', function () {
|
|
var data = '<message>hello, world</message>';
|
|
var result = transformData(data, {'content-type': 'text/xml'}, 200, defaults.transformResponse);
|
|
assert.strictEqual(result, data);
|
|
});
|
|
});
|
|
describe('204 request', function () {
|
|
it('does not parse the empty string', function () {
|
|
var data = '';
|
|
var result = transformData(data, {'content-type': undefined}, 204, defaults.transformResponse);
|
|
assert.strictEqual(result, '');
|
|
});
|
|
it('does not parse undefined', function () {
|
|
var data = undefined;
|
|
var result = transformData(data, {'content-type': undefined}, 200, defaults.transformResponse);
|
|
assert.strictEqual(result, data);
|
|
});
|
|
});
|
|
});
|