提交 5e81cd1e 编写于 作者: 雪洛's avatar 雪洛

test: 增加云对象数字错误码测试例

上级 8fceccbd
...@@ -12,6 +12,7 @@ describe('unicloud-import-object', () => { ...@@ -12,6 +12,7 @@ describe('unicloud-import-object', () => {
it('importObject', async () => { it('importObject', async () => {
await page.callMethod('addTodo') await page.callMethod('addTodo')
await page.callMethod('fail') await page.callMethod('fail')
await page.callMethod('failWithNumberErrCode')
await page.callMethod('success') await page.callMethod('success')
const { const {
...@@ -20,12 +21,14 @@ describe('unicloud-import-object', () => { ...@@ -20,12 +21,14 @@ describe('unicloud-import-object', () => {
returnTodoTitle, returnTodoTitle,
returnTodoContent, returnTodoContent,
failErrCode, failErrCode,
failWithNumberErrCode,
successErrCode, successErrCode,
} = await page.data() } = await page.data()
expect(returnTodoTitle).toBe(todoTitle) expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent) expect(returnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE') expect(failErrCode).toBe('TEST_ERROR_CODE')
expect(failWithNumberErrCode).toBe(-1)
expect(successErrCode).toBe(0) expect(successErrCode).toBe(0)
}) })
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
<view class="uni-btn-v uni-common-mt"> <view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="fail">云对象失败调用</button> <button type="primary" @tap="fail">云对象失败调用</button>
</view> </view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="failWithNumberErrCode">云对象数字错误码</button>
</view>
<view class="uni-btn-v uni-common-mt"> <view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="success">云对象成功调用</button> <button type="primary" @tap="success">云对象成功调用</button>
</view> </view>
...@@ -34,6 +37,7 @@ ...@@ -34,6 +37,7 @@
returnTodoTitle: '', returnTodoTitle: '',
returnTodoContent: '', returnTodoContent: '',
failErrCode: '', failErrCode: '',
failWithNumberErrCode: 0,
successErrCode: -1, successErrCode: -1,
isUniTest: false isUniTest: false
} }
...@@ -104,6 +108,24 @@ ...@@ -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<void> { async success() : Promise<void> {
const todo = uniCloud.importObject('todo', { const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest customUI: this.isUniTest
......
...@@ -31,6 +31,12 @@ module.exports = { ...@@ -31,6 +31,12 @@ module.exports = {
errMsg: '[预期内的报错]执行失败', errMsg: '[预期内的报错]执行失败',
} }
}, },
async failWithNumberErrCode() {
return {
errCode: -1,
errMsg: '[预期内的报错]执行失败',
}
},
async success() { async success() {
return { return {
errCode: 0, errCode: 0,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册