Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
03aa2702
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
03aa2702
编写于
4月 18, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 增加uniCloud使用泛型测试例
上级
04d14289
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
2 deletion
+72
-2
pages/API/unicloud-call-function/unicloud-call-function.test.js
...API/unicloud-call-function/unicloud-call-function.test.js
+9
-1
pages/API/unicloud-call-function/unicloud-call-function.uvue
pages/API/unicloud-call-function/unicloud-call-function.uvue
+30
-0
pages/API/unicloud-import-object/unicloud-import-object.test.js
...API/unicloud-import-object/unicloud-import-object.test.js
+5
-0
pages/API/unicloud-import-object/unicloud-import-object.uvue
pages/API/unicloud-import-object/unicloud-import-object.uvue
+28
-1
未找到文件。
pages/API/unicloud-call-function/unicloud-call-function.test.js
浏览文件 @
03aa2702
...
...
@@ -14,7 +14,7 @@ describe('unicloud-call-function', () => {
await
page
.
callMethod
(
'
callFunction
'
)
const
{
callFunctionResult
,
callFunctionError
callFunctionError
,
}
=
await
page
.
data
()
console
.
error
(
callFunctionResult
)
console
.
error
(
callFunctionError
)
...
...
@@ -22,4 +22,12 @@ describe('unicloud-call-function', () => {
expect
(
callFunctionResult
[
'
event
'
][
'
num
'
]).
toBe
(
1
)
expect
(
callFunctionResult
[
'
event
'
][
'
str
'
]).
toBe
(
'
ABC
'
)
})
it
(
'
callFunctionWithGeneric
'
,
async
()
=>
{
await
page
.
callMethod
(
'
callFunctionWithGeneric
'
)
const
{
genericDemoShowMessage
,
}
=
await
page
.
data
()
expect
(
genericDemoShowMessage
).
toBe
(
"
Hello uniCloud function
"
)
})
})
pages/API/unicloud-call-function/unicloud-call-function.uvue
浏览文件 @
03aa2702
...
...
@@ -7,6 +7,7 @@
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="callFunction">请求云函数</button>
<button type="primary" @click="callFunctionWithGeneric">请求云函数传入泛型</button>
</view>
</view>
</view>
...
...
@@ -22,6 +23,7 @@
title: '请求云函数',
callFunctionResult: {},
callFunctionError: {},
genericDemoShowMessage: '',
isUniTest: false
}
},
...
...
@@ -44,6 +46,34 @@
console.log(title, content)
}
},
async callFunctionWithGeneric() : Promise<void> {
type EchoCfResult = {
showMessage: string
}
uni.showLoading({
title: '加载中...'
})
await uniCloud.callFunction<EchoCfResult>({
name: 'echo-cf',
data: {
num: 1,
str: 'ABC'
}
}).then(res => {
const result = res.result
uni.hideLoading()
this.genericDemoShowMessage = result.showMessage
this.notify(result.showMessage, '提示')
}).catch((err : any | null) => {
const error = err as UniCloudError
this.callFunctionError = {
errCode: error.errCode,
errMsg: error.errMsg
}
uni.hideLoading()
this.notify(error.errMsg, '错误')
})
},
async callFunction() : Promise<void> {
uni.showLoading({
title: '加载中...'
...
...
pages/API/unicloud-import-object/unicloud-import-object.test.js
浏览文件 @
03aa2702
...
...
@@ -11,6 +11,7 @@ describe('unicloud-import-object', () => {
})
it
(
'
importObject
'
,
async
()
=>
{
await
page
.
callMethod
(
'
addTodo
'
)
await
page
.
callMethod
(
'
addTodoWithGeneric
'
)
await
page
.
callMethod
(
'
fail
'
)
await
page
.
callMethod
(
'
failWithNumberErrCode
'
)
await
page
.
callMethod
(
'
success
'
)
...
...
@@ -20,6 +21,8 @@ describe('unicloud-import-object', () => {
todoContent
,
returnTodoTitle
,
returnTodoContent
,
genericDemoReturnTodoTitle
,
genericDemoReturnTodoContent
,
failErrCode
,
failNumberErrCode
,
successErrCode
,
...
...
@@ -27,6 +30,8 @@ describe('unicloud-import-object', () => {
expect
(
returnTodoTitle
).
toBe
(
todoTitle
)
expect
(
returnTodoContent
).
toBe
(
todoContent
)
expect
(
genericDemoReturnTodoTitle
).
toBe
(
todoTitle
)
expect
(
genericDemoReturnTodoContent
).
toBe
(
todoContent
)
expect
(
failErrCode
).
toBe
(
'
TEST_ERROR_CODE
'
)
expect
(
failNumberErrCode
).
toBe
(
-
1
)
expect
(
successErrCode
).
toBe
(
0
)
...
...
pages/API/unicloud-import-object/unicloud-import-object.uvue
浏览文件 @
03aa2702
...
...
@@ -8,6 +8,9 @@
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodo">添加Todo</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodoWithGeneric">添加Todo传入泛型</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="randomFail">随机触发失败重试</button>
</view>
...
...
@@ -36,6 +39,8 @@
todoContent: '熟悉uts语法',
returnTodoTitle: '',
returnTodoContent: '',
genericDemoReturnTodoTitle: '',
genericDemoReturnTodoContent: '',
failErrCode: '',
failNumberErrCode: 0,
successErrCode: -1,
...
...
@@ -60,11 +65,33 @@
})
const title = this.todoTitle
const content = this.todoContent
await todo.add(title, content).then((res : UTSJSONObject) => {
await todo.add
<UTSJSONObject>
(title, content).then((res : UTSJSONObject) => {
this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) => {
console.log(err)
const error = err as UniCloudError
console.error(error)
})
},
async addTodoWithGeneric() : Promise<void> {
type AddTodoResult = {
title: string,
content: string,
showMessage: string
}
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle
const content = this.todoContent
await todo.add<AddTodoResult>(title, content).then((res : AddTodoResult) => {
this.genericDemoReturnTodoTitle = res.title
this.genericDemoReturnTodoContent = res.content
this.notify(res.showMessage, '提示')
}).catch((err : any | null) => {
console.log(err)
const error = err as UniCloudError
console.error(error)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录