Skip to content

Commit

Permalink
fix: avoid generating the same apiFn's key (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
BuptStEve authored Dec 16, 2019
1 parent ccfde94 commit 3d54b0d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions examples/apis-mp/fake-wx.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default {
}),
useGlobalMiddleware: true,
},
/**
* anotherFail
*/
{
path: 'fail',
name: 'anotherFail',
},
/**
* array-data
*/
Expand Down
3 changes: 2 additions & 1 deletion examples/apis-mp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const fakeWxApi: {
'typeGet': ReqFnWithAnyParams
'noBeforeFn': ReqFnWithAnyParams
'navLoading': ReqFnWithAnyParams
'anotherFail': ReqFnWithAnyParams
'hideLoading': ReqFnWithAnyParams
'unknownType': ReqFnWithAnyParams
'arrayData': ReqFn & {
Expand All @@ -39,4 +40,4 @@ export const fakeWxApi: {
options?: RuntimeOptions
): Promise<T>
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tua-api",
"version": "1.4.1",
"version": "1.4.2",
"description": "🏗 A common tool helps converting configs to api functions",
"main": "dist/TuaApi.cjs.js",
"module": "dist/TuaApi.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class TuaApi {
)
}

apiFn.key = `${prefix}/${path}`
apiFn.key = `${prefix}/${apiName}`
apiFn.mock = mock
apiFn.params = params

Expand Down
4 changes: 4 additions & 0 deletions test/__tests__/wx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ describe('fake wx requests', () => {
wx.__TEST_DATA__ = {}
})

test('same key', () => {
expect(fakeWxApi.fail.key).not.toEqual(fakeWxApi.anotherFail.key)
})

test('object-data', async () => {
wx.__TEST_DATA__ = { testData: testObjData }
const resData = await fakeWxApi.objectData({ param3: '123' })
Expand Down

0 comments on commit 3d54b0d

Please sign in to comment.