2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-27 14:47:43 +03:00
Files
axios/test/specs/cancel/CanceledError.spec.js
T
Julian Dax 1c6a86dd2c fix: turn AxiosError into a native error (#5394) (#5558)
* fix: turn AxiosError into a native error (#5394)

Being an object returned by the 'Error' constructor turns something into a 'native error'.

* fix: simplify code in AxiosError

* fix: simplify code in AxiosError

* refactor: implement AxiosError as a class

* refactor: implement CanceledError as a class

This turns CanceledError into a native error.

* refactor: simplify AxiosError.toJSON

* fix: improve error code handling in `AxiosError.from`

If no error code is provided, use the code from the underlying error.

* fix: set error status in `AxiosError.constructor`

If a response is passed to the constructor, set the response status as a property.

* fix: remove unnecessary async

---------

Co-authored-by: Jay <jasonsaayman@gmail.com>
2025-11-11 19:06:10 +02:00

22 lines
896 B
JavaScript

import CanceledError from '../../../lib/cancel/CanceledError';
describe('Cancel', function() {
describe('toString', function() {
it('returns correct result when message is not specified', function() {
const cancel = new CanceledError();
expect(cancel.toString()).toBe('CanceledError: canceled');
});
it('returns correct result when message is specified', function() {
const cancel = new CanceledError('Operation has been canceled.');
expect(cancel.toString()).toBe('CanceledError: Operation has been canceled.');
});
});
it('should be a native error as checked by the NodeJS `isNativeError` function', function (){
if((typeof process !== 'undefined') && (process.release.name === 'node')){
let {isNativeError} = require('node:util/types');
expect(isNativeError(new CanceledError("My Canceled Error"))).toBeTruthy();
}
});
});