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>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import Axios from '../../../lib/core/Axios.js';
|
|
import assert from 'assert';
|
|
|
|
describe('Axios', function () {
|
|
describe('handle un-writable error stack', function () {
|
|
async function testUnwritableErrorStack(stackAttributes) {
|
|
const axios = new Axios({});
|
|
// mock axios._request to return an Error with an un-writable stack property
|
|
axios._request = () => {
|
|
const mockError = new Error('test-error');
|
|
Object.defineProperty(mockError, 'stack', stackAttributes);
|
|
throw mockError;
|
|
};
|
|
try {
|
|
await axios.request('test-url', {});
|
|
} catch (e) {
|
|
assert.strictEqual(e.message, 'test-error');
|
|
}
|
|
}
|
|
|
|
it('should support errors with a defined but un-writable stack', async function () {
|
|
await testUnwritableErrorStack({ value: {}, writable: false });
|
|
});
|
|
|
|
it('should support errors with an undefined and un-writable stack', async function () {
|
|
await testUnwritableErrorStack({ value: undefined, writable: false });
|
|
});
|
|
|
|
it('should support errors with a custom getter/setter for the stack property', async function () {
|
|
await testUnwritableErrorStack({
|
|
get: () => ({}),
|
|
set: () => {
|
|
throw new Error('read-only');
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should support errors with a custom getter/setter for the stack property (null case)', async function () {
|
|
await testUnwritableErrorStack({
|
|
get: () => null,
|
|
set: () => {
|
|
throw new Error('read-only');
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should not throw if the config argument is omitted', () => {
|
|
const axios = new Axios();
|
|
|
|
assert.deepStrictEqual(axios.defaults, {});
|
|
});
|
|
});
|