From 5e81cd1e815d7862ef920c7fca64f007517dd04b Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Mon, 4 Mar 2024 13:48:13 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E4=BA=91=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E6=95=B0=E5=AD=97=E9=94=99=E8=AF=AF=E7=A0=81=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unicloud-import-object.test.js | 3 +++ .../unicloud-import-object.uvue | 22 +++++++++++++++++++ .../cloudfunctions/todo/index.obj.js | 6 +++++ 3 files changed, 31 insertions(+) diff --git a/pages/API/unicloud-import-object/unicloud-import-object.test.js b/pages/API/unicloud-import-object/unicloud-import-object.test.js index 5e8662bd..b9caa871 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.test.js +++ b/pages/API/unicloud-import-object/unicloud-import-object.test.js @@ -12,6 +12,7 @@ describe('unicloud-import-object', () => { it('importObject', async () => { await page.callMethod('addTodo') await page.callMethod('fail') + await page.callMethod('failWithNumberErrCode') await page.callMethod('success') const { @@ -20,12 +21,14 @@ describe('unicloud-import-object', () => { returnTodoTitle, returnTodoContent, failErrCode, + failWithNumberErrCode, successErrCode, } = await page.data() expect(returnTodoTitle).toBe(todoTitle) expect(returnTodoContent).toBe(todoContent) expect(failErrCode).toBe('TEST_ERROR_CODE') + expect(failWithNumberErrCode).toBe(-1) expect(successErrCode).toBe(0) }) diff --git a/pages/API/unicloud-import-object/unicloud-import-object.uvue b/pages/API/unicloud-import-object/unicloud-import-object.uvue index 8ee4f6cb..e2687221 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.uvue +++ b/pages/API/unicloud-import-object/unicloud-import-object.uvue @@ -14,6 +14,9 @@ + + + @@ -34,6 +37,7 @@ returnTodoTitle: '', returnTodoContent: '', failErrCode: '', + failWithNumberErrCode: 0, successErrCode: -1, isUniTest: false } @@ -104,6 +108,24 @@ } }) }, + async failWithNumberErrCode(){ + const todo = uniCloud.importObject('todo', { + customUI: this.isUniTest + }) + await todo.fail().then((res : UTSJSONObject) => { + this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误') + console.log('todo.fail: ', res); + }).catch((err : any | null) => { + const error = err as UniCloudError + this.failWithNumberErrCode = error.errCode as number + console.error(error) + if (this.isUniTest) { + uni.showToast({ + title: error.errMsg + }) + } + }) + }, async success() : Promise { const todo = uniCloud.importObject('todo', { customUI: this.isUniTest diff --git a/uniCloud-aliyun/cloudfunctions/todo/index.obj.js b/uniCloud-aliyun/cloudfunctions/todo/index.obj.js index 4680891d..51a32594 100644 --- a/uniCloud-aliyun/cloudfunctions/todo/index.obj.js +++ b/uniCloud-aliyun/cloudfunctions/todo/index.obj.js @@ -31,6 +31,12 @@ module.exports = { errMsg: '[预期内的报错]执行失败', } }, + async failWithNumberErrCode() { + return { + errCode: -1, + errMsg: '[预期内的报错]执行失败', + } + }, async success() { return { errCode: 0, -- GitLab