2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/test/unit/helpers/toFormData.js
T
Jay ef3711d1b3 feat: implement prettier and fix all issues (#7385)
* 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>
2026-02-14 16:59:48 +02:00

54 lines
1.2 KiB
JavaScript

import assert from 'assert';
import toFormData from '../../../lib/helpers/toFormData.js';
import FormData from 'form-data';
describe('helpers::toFormData', function () {
it('should convert a flat object to FormData', function () {
const data = {
foo: 'bar',
baz: 123,
};
const formData = toFormData(data, new FormData());
assert.ok(formData instanceof FormData);
// form-data package specific checks
assert.ok(formData._streams.length > 0);
});
it('should convert a nested object to FormData', function () {
const data = {
foo: {
bar: 'baz',
},
};
const formData = toFormData(data, new FormData());
assert.ok(formData instanceof FormData);
});
it('should throw Error on circular reference', function () {
const data = {
foo: 'bar',
};
data.self = data;
try {
toFormData(data, new FormData());
assert.fail('Should have thrown an error');
} catch (e) {
assert.strictEqual(e.message, 'Circular reference detected in self');
}
});
it('should handle arrays', function () {
const data = {
arr: [1, 2, 3],
};
const formData = toFormData(data, new FormData());
assert.ok(formData instanceof FormData);
});
});