Skip to content

Commit 17825c7

Browse files
authored
fix(core): close #33, do not pass api's params to axios (#34)
1 parent a70c67d commit 17825c7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tua-api",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "🏗 A common tool helps converting configs to api functions",
55
"main": "dist/TuaApi.cjs.js",
66
"module": "dist/TuaApi.esm.js",

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,14 @@ class TuaApi {
139139
data: method === 'GET' ? {} : data,
140140
method,
141141
...axiosOptions,
142-
...rest,
143142
}
144143

145144
return getAxiosPromise(params)
146145
}
147146

148147
// 对于 post 请求使用 axios
149148
return method === 'POST'
150-
? getAxiosPromise({ url, data, ...axiosOptions, ...rest })
149+
? getAxiosPromise({ url, data, ...axiosOptions })
151150
: getFetchJsonpPromise({
152151
url: fullUrl,
153152
jsonpOptions: { ...jsonpOptions, callbackName },

test/__tests__/axios.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const params = {
1313

1414
const reqAPUrl = `http://example-base.com/fake-post/array-params`
1515
const reqOPUrl = `http://example-base.com/fake-post/object-params`
16+
const reqGOPUrl = `http://example-base.com/fake-get/object-params`
1617
const reqOHUrl = `http://example-test.com/fake-post/own-host`
1718
const reqTAUrl = `http://example-base.com/fake-get/req-type-axios?asyncCp=asyncCp`
1819
const reqEAPUrl = `http://example-base.com/fake-post/empty-array-params`
@@ -56,6 +57,10 @@ describe('error handling', () => {
5657
})
5758

5859
describe('fake get requests', () => {
60+
beforeEach(() => {
61+
mock.resetHistory()
62+
})
63+
5964
test('req-type-axios', async () => {
6065
const data = { code: 0, data: 'req-type-axios' }
6166
mock.onGet(reqTAUrl).reply(200, data)
@@ -75,6 +80,15 @@ describe('fake get requests', () => {
7580

7681
expect(resData).toEqual(data)
7782
})
83+
84+
test('required param', async () => {
85+
const data = [ 0, 'array data' ]
86+
mock.onGet(reqGOPUrl + `?param1=1217&param2=steve&param3=young`).reply(200, data)
87+
const resData = await fakeGetApi.op({ param3: 'young' }, { reqType: 'axios' })
88+
89+
expect(mock.history.get[0].params).toBe(undefined)
90+
expect(resData).toEqual({ code: 0, data: 'array data' })
91+
})
7892
})
7993

8094
describe('fake post requests', () => {

0 commit comments

Comments
 (0)