void 0
parent
ec1587111a
commit
1d5cc0527e
|
@ -28,7 +28,7 @@ export default function adaptive(): Adapter | undefined {
|
||||||
|
|
||||||
let adapter: Adapter | undefined;
|
let adapter: Adapter | undefined;
|
||||||
|
|
||||||
while (stack.length !== 0 && adapter === undefined) {
|
while (stack.length !== 0 && adapter === void 0) {
|
||||||
try {
|
try {
|
||||||
adapter = (stack.shift() as () => Adapter)();
|
adapter = (stack.shift() as () => Adapter)();
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default class AxiosClass implements Axios {
|
||||||
}
|
}
|
||||||
|
|
||||||
public options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('options', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('options', url, void 0, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
|
@ -67,11 +67,11 @@ export default class AxiosClass implements Axios {
|
||||||
}
|
}
|
||||||
|
|
||||||
public trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('trace', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('trace', url, void 0, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('connect', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('connect', url, void 0, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,7 @@ export default function dispatchRequest(config: AxiosRequestConfig): Promise<Axi
|
||||||
if (!isCancel(reason)) {
|
if (!isCancel(reason)) {
|
||||||
throwIfCancellationRequested(config);
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
if (reason.response !== undefined) {
|
if (reason.response !== void 0) {
|
||||||
reason.response.data = transformData(reason.response.data, reason.response.headers, config.transformResponse);
|
reason.response.data = transformData(reason.response.data, reason.response.headers, config.transformResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { methodToLowercase } from './transformMethod';
|
||||||
export default function flattenHeaders(config: AxiosRequestConfig): Headers {
|
export default function flattenHeaders(config: AxiosRequestConfig): Headers {
|
||||||
const { headers } = config;
|
const { headers } = config;
|
||||||
|
|
||||||
if (headers === undefined) {
|
if (headers === void 0) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ type DeepMergeConfigKey = 'params' | 'headers';
|
||||||
*/
|
*/
|
||||||
function onlyFromConfig2(keys: OnlyFromConfig2Key[], config: AxiosRequestConfig, config2: AxiosRequestConfig) {
|
function onlyFromConfig2(keys: OnlyFromConfig2Key[], config: AxiosRequestConfig, config2: AxiosRequestConfig) {
|
||||||
keys.forEach((key) => {
|
keys.forEach((key) => {
|
||||||
if (config2[key] !== undefined) {
|
if (config2[key] !== void 0) {
|
||||||
config[key] = config2[key] as any;
|
config[key] = config2[key] as any;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -51,9 +51,9 @@ function priorityFromConfig2(
|
||||||
config2: AxiosRequestConfig
|
config2: AxiosRequestConfig
|
||||||
) {
|
) {
|
||||||
keys.forEach((key) => {
|
keys.forEach((key) => {
|
||||||
if (config2[key] !== undefined) {
|
if (config2[key] !== void 0) {
|
||||||
config[key] = config2[key] as any;
|
config[key] = config2[key] as any;
|
||||||
} else if (config1[key] !== undefined) {
|
} else if (config1[key] !== void 0) {
|
||||||
config[key] = config1[key] as any;
|
config[key] = config1[key] as any;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default function request(config: AxiosRequestConfig): Promise<AxiosRespon
|
||||||
reject(createError(message, config, requestConfig, response));
|
reject(createError(message, config, requestConfig, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adapter === undefined) {
|
if (adapter === void 0) {
|
||||||
catchError('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
catchError('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -41,7 +41,7 @@ export default function request(config: AxiosRequestConfig): Promise<AxiosRespon
|
||||||
function handleResponse(res: Response): void {
|
function handleResponse(res: Response): void {
|
||||||
const response = transformResponse(res, config);
|
const response = transformResponse(res, config);
|
||||||
|
|
||||||
if (config.validateStatus === undefined || config.validateStatus(response.status)) {
|
if (config.validateStatus === void 0 || config.validateStatus(response.status)) {
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} else {
|
} else {
|
||||||
catchError(`请求失败,状态码为 ${response.status}`, response);
|
catchError(`请求失败,状态码为 ${response.status}`, response);
|
||||||
|
@ -57,9 +57,9 @@ export default function request(config: AxiosRequestConfig): Promise<AxiosRespon
|
||||||
|
|
||||||
// 如果存在取消令牌
|
// 如果存在取消令牌
|
||||||
// 则调用取消令牌里的 listener 监听用户的取消操作
|
// 则调用取消令牌里的 listener 监听用户的取消操作
|
||||||
if (cancelToken !== undefined) {
|
if (cancelToken !== void 0) {
|
||||||
cancelToken.listener.then(function onCanceled(reason): void {
|
cancelToken.listener.then(function onCanceled(reason): void {
|
||||||
if (task !== undefined) {
|
if (task !== void 0) {
|
||||||
task.abort();
|
task.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default function transformData(
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
transforms?: TransformData | TransformData[]
|
transforms?: TransformData | TransformData[]
|
||||||
): Data {
|
): Data {
|
||||||
if (transforms === undefined) {
|
if (transforms === void 0) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ function paramsSerialization(params: AnyObject): string {
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
|
|
||||||
Object.entries(params).forEach(function encodeKeyValue([key, value]): void {
|
Object.entries(params).forEach(function encodeKeyValue([key, value]): void {
|
||||||
if (value === null || value === undefined || value !== value) {
|
if (value === null || value === void 0 || value !== value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe('测试 src/adaptive.ts', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('适配失败', () => {
|
it('适配失败', () => {
|
||||||
global.wx = undefined;
|
global.wx = void 0;
|
||||||
|
|
||||||
expect(adaptive()).toBeUndefined();
|
expect(adaptive()).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import axios from '../src/axios';
|
||||||
|
|
||||||
describe('测试 src/axios.ts', () => {
|
describe('测试 src/axios.ts', () => {
|
||||||
it('default', () => {
|
it('default', () => {
|
||||||
axios('/test').then(undefined, (error) => {
|
axios('/test').then(void 0, (error) => {
|
||||||
expect(error.isAxiosError).toBe(true);
|
expect(error.isAxiosError).toBe(true);
|
||||||
expect(error.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
expect(error.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe('测试 src/core/Axios.ts', () => {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: '',
|
data: '',
|
||||||
})
|
})
|
||||||
.then(undefined, (error) => expect(error.data).toBe('interceptors_response'));
|
.then(void 0, (error) => expect(error.data).toBe('interceptors_response'));
|
||||||
|
|
||||||
instance.interceptors.request.use((config) => Promise.reject(config));
|
instance.interceptors.request.use((config) => Promise.reject(config));
|
||||||
|
|
||||||
|
@ -58,6 +58,6 @@ describe('测试 src/core/Axios.ts', () => {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: '',
|
data: '',
|
||||||
})
|
})
|
||||||
.then(undefined, (error) => expect(error.method).toBe('post'));
|
.then(void 0, (error) => expect(error.method).toBe('post'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,8 +15,8 @@ describe('测试 src/core/InterceptorManager.ts', () => {
|
||||||
const interceptor = new InterceptorManager();
|
const interceptor = new InterceptorManager();
|
||||||
const executor1 = jest.fn();
|
const executor1 = jest.fn();
|
||||||
const executor2 = jest.fn();
|
const executor2 = jest.fn();
|
||||||
const id1 = interceptor.use(() => undefined);
|
const id1 = interceptor.use(() => void 0);
|
||||||
const id2 = interceptor.use(() => undefined);
|
const id2 = interceptor.use(() => void 0);
|
||||||
interceptor.forEach(executor1);
|
interceptor.forEach(executor1);
|
||||||
|
|
||||||
// executor1 应该被执行了两次
|
// executor1 应该被执行了两次
|
||||||
|
@ -49,7 +49,7 @@ describe('测试 src/core/InterceptorManager.ts', () => {
|
||||||
const interceptor = new InterceptorManager();
|
const interceptor = new InterceptorManager();
|
||||||
|
|
||||||
interceptor.use(
|
interceptor.use(
|
||||||
() => undefined,
|
() => void 0,
|
||||||
(error: any) => {
|
(error: any) => {
|
||||||
expect(error).toBe('error');
|
expect(error).toBe('error');
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import isCancel from '../../src/cancel/isCancel';
|
||||||
|
|
||||||
describe('测试 src/core/dispatchRequest.ts', () => {
|
describe('测试 src/core/dispatchRequest.ts', () => {
|
||||||
it('默认', () => {
|
it('默认', () => {
|
||||||
dispatchRequest({}).then(undefined, (err) => {
|
dispatchRequest({}).then(void 0, (err) => {
|
||||||
expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,7 @@ describe('测试 src/core/dispatchRequest.ts', () => {
|
||||||
validateStatus(status) {
|
validateStatus(status) {
|
||||||
return status === -1;
|
return status === -1;
|
||||||
},
|
},
|
||||||
}).then(undefined, (err) => expect(err.response.status).toBe(200));
|
}).then(void 0, (err) => expect(err.response.status).toBe(200));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('自定义错误处理', () => {
|
it('自定义错误处理', () => {
|
||||||
|
@ -34,7 +34,7 @@ describe('测试 src/core/dispatchRequest.ts', () => {
|
||||||
error.errorHandler = true;
|
error.errorHandler = true;
|
||||||
return error;
|
return error;
|
||||||
},
|
},
|
||||||
}).then(undefined, (error) => expect(error.errorHandler).toBe(true));
|
}).then(void 0, (error) => expect(error.errorHandler).toBe(true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('取消请求', () => {
|
it('取消请求', () => {
|
||||||
|
@ -50,6 +50,6 @@ describe('测试 src/core/dispatchRequest.ts', () => {
|
||||||
cancelToken: new CancelToken(function executor(c) {
|
cancelToken: new CancelToken(function executor(c) {
|
||||||
cancel = c;
|
cancel = c;
|
||||||
}),
|
}),
|
||||||
}).then(undefined, (err) => expect(isCancel(err)).toBe(true));
|
}).then(void 0, (err) => expect(isCancel(err)).toBe(true));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('测试 src/core/mergeConfig.ts', () => {
|
||||||
|
|
||||||
expect(mergeConfig({ baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' });
|
expect(mergeConfig({ baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' });
|
||||||
|
|
||||||
expect(mergeConfig(undefined, { baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' });
|
expect(mergeConfig(void 0, { baseURL: 'https://www.xxx.com' })).toEqual({ baseURL: 'https://www.xxx.com' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('只取 config2', () => {
|
it('只取 config2', () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import isCancel from '../../src/cancel/isCancel';
|
||||||
|
|
||||||
describe('测试 src/core/request.ts', () => {
|
describe('测试 src/core/request.ts', () => {
|
||||||
it('默认', () => {
|
it('默认', () => {
|
||||||
request({}).then(undefined, (err) =>
|
request({}).then(void 0, (err) =>
|
||||||
expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台')
|
expect(err.message).toBe('平台适配失败,您需要参阅文档使用自定义适配器手动适配当前平台')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,7 @@ describe('测试 src/core/request.ts', () => {
|
||||||
|
|
||||||
return 'task';
|
return 'task';
|
||||||
},
|
},
|
||||||
}).then(undefined, (err) => expect(err.message).toBe('配置不正确或者网络异常'));
|
}).then(void 0, (err) => expect(err.message).toBe('配置不正确或者网络异常'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('取消请求', () => {
|
it('取消请求', () => {
|
||||||
|
@ -31,6 +31,6 @@ describe('测试 src/core/request.ts', () => {
|
||||||
cancelToken: new CancelToken(function executor(c) {
|
cancelToken: new CancelToken(function executor(c) {
|
||||||
c();
|
c();
|
||||||
}),
|
}),
|
||||||
}).then(undefined, (err) => expect(isCancel(err)).toBe(true));
|
}).then(void 0, (err) => expect(isCancel(err)).toBe(true));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,16 +5,16 @@ describe('测试 src/core/transformRequest.ts', () => {
|
||||||
expect(transformRequest({})).toEqual({
|
expect(transformRequest({})).toEqual({
|
||||||
url: '/',
|
url: '/',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: undefined,
|
headers: void 0,
|
||||||
data: undefined,
|
data: void 0,
|
||||||
dataType: undefined,
|
dataType: void 0,
|
||||||
enableCache: undefined,
|
enableCache: void 0,
|
||||||
enableHttp2: undefined,
|
enableHttp2: void 0,
|
||||||
enableQuic: undefined,
|
enableQuic: void 0,
|
||||||
header: undefined,
|
header: void 0,
|
||||||
responseType: undefined,
|
responseType: void 0,
|
||||||
sslVerify: undefined,
|
sslVerify: void 0,
|
||||||
timeout: undefined,
|
timeout: void 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ describe('测试 src/core/transformResponse.ts', () => {
|
||||||
data: {},
|
data: {},
|
||||||
headers: {},
|
headers: {},
|
||||||
config: {},
|
config: {},
|
||||||
cookies: undefined,
|
cookies: void 0,
|
||||||
profile: undefined,
|
profile: void 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ describe('测试 src/core/transformResponse.ts', () => {
|
||||||
data: {},
|
data: {},
|
||||||
headers: { status: 'ok' },
|
headers: { status: 'ok' },
|
||||||
config: {},
|
config: {},
|
||||||
cookies: undefined,
|
cookies: void 0,
|
||||||
profile: undefined,
|
profile: void 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('statusCode + header', () => {
|
it('statusCode + header', () => {
|
||||||
|
@ -31,8 +31,8 @@ describe('测试 src/core/transformResponse.ts', () => {
|
||||||
data: {},
|
data: {},
|
||||||
headers: { status: 'ok' },
|
headers: { status: 'ok' },
|
||||||
config: {},
|
config: {},
|
||||||
cookies: undefined,
|
cookies: void 0,
|
||||||
profile: undefined,
|
profile: void 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe('测试 src/helpers/buildURL.ts', () => {
|
||||||
expect(
|
expect(
|
||||||
buildURL('/test', {
|
buildURL('/test', {
|
||||||
null: null,
|
null: null,
|
||||||
undefined: undefined,
|
undefined: void 0,
|
||||||
NaN: NaN,
|
NaN: NaN,
|
||||||
})
|
})
|
||||||
).toBe('/test');
|
).toBe('/test');
|
||||||
|
|
Loading…
Reference in New Issue