From 759a61807f5d95b3c67054505d9a20f6064ec58c Mon Sep 17 00:00:00 2001 From: StEve Young <2747745470@qq.com> Date: Thu, 25 Jul 2019 20:23:59 +0800 Subject: [PATCH] fix(utils): close #37, fix object params (#38) --- package.json | 2 +- src/utils/params.js | 4 +++- test/__tests__/utils.test.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3a132fc..0f111de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tua-api", - "version": "1.3.2", + "version": "1.3.3", "description": "🏗 A common tool helps converting configs to api functions", "main": "dist/TuaApi.cjs.js", "module": "dist/TuaApi.esm.js", diff --git a/src/utils/params.js b/src/utils/params.js index 3fefdc2..21b6d51 100644 --- a/src/utils/params.js +++ b/src/utils/params.js @@ -70,7 +70,9 @@ const getDefaultParamObj = ({ } } - return { [key]: val } + const returnVal = typeof val === 'object' ? '' : val + + return { [key]: returnVal } }), reduce(merge, commonParams) )(params) diff --git a/test/__tests__/utils.test.js b/test/__tests__/utils.test.js index 1324078..60452f4 100644 --- a/test/__tests__/utils.test.js +++ b/test/__tests__/utils.test.js @@ -38,6 +38,10 @@ test('getDefaultParamObj', () => { commonParams: { c: '3' }, })).toEqual({ b: '2', c: '3' }) + expect(getDefaultParamObj({ + params: { a: { required: false } }, + })).toEqual({ a: '' }) + expect(() => getDefaultParamObj({ params: { b: { required: true } }, apiName: 'steve',