fix: 配置原始请求方法丢失
parent
8b6eed2d6d
commit
c107171eba
|
@ -26,7 +26,6 @@ export function dispatchRequest(config: AxiosRequestConfig) {
|
|||
assert(isString(config.url), 'url 不是一个 string');
|
||||
assert(isString(config.method), 'method 不是一个 string');
|
||||
|
||||
config.method = config.method!.toUpperCase() as AxiosRequestMethod;
|
||||
config.headers = flattenHeaders(config);
|
||||
|
||||
// 可以携带 data 的请求方法,转换 data
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
AxiosAdapterResponse,
|
||||
AxiosAdapterResponseError,
|
||||
AxiosAdapterPlatformTask,
|
||||
AxiosAdapterRequestMethod,
|
||||
} from '../adpater/createAdapter';
|
||||
import { isCancelToken } from './cancel';
|
||||
import { AxiosErrorResponse, createError } from './createError';
|
||||
|
@ -26,8 +27,9 @@ export function request(config: AxiosRequestConfig) {
|
|||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
const adapterConfig: AxiosAdapterRequestConfig = {
|
||||
...(config as AxiosAdapterRequestConfig),
|
||||
url: transformURL(config),
|
||||
type: generateType(config),
|
||||
url: transformURL(config),
|
||||
method: config.method!.toUpperCase() as AxiosAdapterRequestMethod,
|
||||
success,
|
||||
fail,
|
||||
};
|
||||
|
|
|
@ -38,18 +38,6 @@ describe('src/request/dispatchRequest.ts', () => {
|
|||
).not.toThrowError();
|
||||
});
|
||||
|
||||
testEachMethods('应该支持 %s 转全大写', (k) => {
|
||||
const c = {
|
||||
adapter: mockAdapter(),
|
||||
url: '/',
|
||||
method: k,
|
||||
};
|
||||
|
||||
dispatchRequest(c);
|
||||
|
||||
expect(c.method).toBe(k.toUpperCase());
|
||||
});
|
||||
|
||||
test('坏的适配器应该抛出异常', () => {
|
||||
expect(
|
||||
dispatchRequest({
|
||||
|
@ -64,7 +52,7 @@ describe('src/request/dispatchRequest.ts', () => {
|
|||
"config": {
|
||||
"adapter": [Function],
|
||||
"headers": {},
|
||||
"method": "GET",
|
||||
"method": "get",
|
||||
"url": "/",
|
||||
},
|
||||
"request": undefined,
|
||||
|
@ -72,7 +60,7 @@ describe('src/request/dispatchRequest.ts', () => {
|
|||
"config": {
|
||||
"adapter": [Function],
|
||||
"headers": {},
|
||||
"method": "GET",
|
||||
"method": "get",
|
||||
"url": "/",
|
||||
},
|
||||
"data": undefined,
|
||||
|
|
|
@ -18,6 +18,7 @@ describe('src/request/request.ts', () => {
|
|||
},
|
||||
baseURL: 'http://api.com',
|
||||
url: 'test',
|
||||
method: 'get' as const,
|
||||
};
|
||||
const c2 = {
|
||||
adapter(config: AnyObject) {
|
||||
|
@ -25,6 +26,7 @@ describe('src/request/request.ts', () => {
|
|||
},
|
||||
baseURL: 'http://api.com',
|
||||
url: 'test/:id',
|
||||
method: 'get' as const,
|
||||
params: {
|
||||
id: 1,
|
||||
},
|
||||
|
@ -46,6 +48,18 @@ describe('src/request/request.ts', () => {
|
|||
request(c3);
|
||||
});
|
||||
|
||||
testEachMethods('应该支持 %s 转全大写', (k) => {
|
||||
const c = {
|
||||
adapter(config: AnyObject) {
|
||||
expect(config.method).toBe(k.toUpperCase());
|
||||
},
|
||||
url: '/',
|
||||
method: k,
|
||||
};
|
||||
|
||||
request(c);
|
||||
});
|
||||
|
||||
testEachMethods('%s 方法应该返回正确的响应体结构', (k) => {
|
||||
const c = {
|
||||
adapter: mockAdapter(),
|
||||
|
|
Loading…
Reference in New Issue