mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
JSON improvements: throw if JSON parsing failed; number, boolean can be passed directly as payload for encoding to JSON #2613, #61, #907 (#3688)
* Draft * Added support for primitive types to be converted to JSON if the request Content-Type is 'application/json'; Added throwing SyntaxError if JSON parsing failed and responseType is json; Added transitional option object; Added options validator to assert transitional options; Added transitional option `silentJSONParsing= true` for backward compatibility; Updated README.md; Updated typings; * Fixed isOlderVersion helper; Fixed typo; Added validator.spec.js; * Added forcedJSONParsing transitional option #2791 * `transformData` is now called in the default configuration context if the function context is not specified (for tests compatibility); * Added `transitional.clarifyTimeoutError` to throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts; Added support of onloadend handler if available instead of onreadystatechange; Added xhr timeout test; Fixed potential bug of xhr adapter with proper handling timeouts&errors (FakeXMLHTTPRequest failed to handle timeouts);
This commit is contained in:
@@ -63,6 +63,51 @@ describe('requests', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('timeouts', function(){
|
||||
beforeEach(function () {
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('should handle timeouts', function (done) {
|
||||
axios({
|
||||
url: '/foo',
|
||||
timeout: 100
|
||||
}).then(function () {
|
||||
fail(new Error('timeout error not caught'));
|
||||
}, function (err) {
|
||||
expect(err instanceof Error).toBe(true);
|
||||
expect(err.code).toEqual('ECONNABORTED');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().responseTimeout();
|
||||
});
|
||||
|
||||
describe('transitional.clarifyTimeoutError', function () {
|
||||
it('should activate throwing ETIMEDOUT instead of ECONNABORTED on request timeouts', function (done) {
|
||||
axios({
|
||||
url: '/foo',
|
||||
timeout: 100,
|
||||
transitional: {
|
||||
clarifyTimeoutError: true
|
||||
}
|
||||
}).then(function () {
|
||||
fail(new Error('timeout error not caught'));
|
||||
}, function (err) {
|
||||
expect(err instanceof Error).toBe(true);
|
||||
expect(err.code).toEqual('ETIMEDOUT');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().responseTimeout();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject on network errors', function (done) {
|
||||
// disable jasmine.Ajax since we're hitting a non-existent server anyway
|
||||
jasmine.Ajax.uninstall();
|
||||
|
||||
Reference in New Issue
Block a user