forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v1.x' into feat/axios-fetch-adapter
- Loading branch information
Showing
2 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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'); | ||
} | ||
}) | ||
}); | ||
}) | ||
}); |