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