Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
4a847ddf
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1625
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4a847ddf
编写于
8月 19, 2024
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增promise静态函数测试例
上级
c0567af5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
116 addition
and
2 deletion
+116
-2
pages/SyntaxCase/index.uvue
pages/SyntaxCase/index.uvue
+15
-2
uni_modules/uts-syntaxcase/utssdk/index.uts
uni_modules/uts-syntaxcase/utssdk/index.uts
+101
-0
未找到文件。
pages/SyntaxCase/index.uvue
浏览文件 @
4a847ddf
...
...
@@ -53,7 +53,10 @@
<view>测试callback:{{ format(testUtsClassInstanceResult['callback']) }}</view>
<button @click="testUtsClassSetter">点击测试class 示例setter方法</button>
<view>测试setter:{{ format(testUtsClassSetterResult) }}</view>
<button @click="testAll">点击测试所有</button>
<button @click="testAll">点击测试所有</button>
<!-- #ifdef APP-IOS -->
<button @click="testPromiseStaticMethod">点击测试promise静态方法</button>
<!-- #endif -->
</view>
<view style="height: 20px;"></view>
</scroll-view>
...
...
@@ -73,6 +76,11 @@
request,
SetterTest,
} from "../../uni_modules/uts-syntaxcase";
// #endif
// #ifdef APP-IOS
import {
testPromiseStaticMethod
} from "@/uni_modules/uts-syntaxcase"
// #endif
let test:Test|null = null
let id = 0
...
...
@@ -441,7 +449,12 @@
} catch (e) {
console.error("testUtsClassSetter", e);
}
},
},
// #ifdef APP-IOS
testPromiseStaticMethod() {
testPromiseStaticMethod()
}
// #endif
}
}
</script>
\ No newline at end of file
uni_modules/uts-syntaxcase/utssdk/index.uts
浏览文件 @
4a847ddf
import
{
RequestTask
,
SyncOptions
,
AsyncOptions
,
SyntaxResult
,
SyncResult
,
TestOptions
}
from
"./interface.uts"
;
import
{
log
}
from
"./utils.uts"
;
// #ifdef APP-IOS
import
{
UTSPromiseAggregateError
,
UTSPromiseFulfilledResult
,
UTSPromiseRejectedResult
}
from
"DCloudUTSFoundation"
;
// #endif
/**
* 导出一个属性
...
...
@@ -121,6 +124,104 @@ export class Test {
}
}
// #ifdef APP-IOS
// #ifdef UNI-APP-X
export
function
testPromiseStaticMethod
()
{
let
p0
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
let
success
=
true
setTimeout
(()
=>
{
if
(
success
)
{
const
res
:
SyntaxResult
=
{
name
:
"pomise 0"
,
}
resolve
(
res
);
}
else
{
reject
(
new
Error
(
"this is promise 0 reject reasion"
))
}
},
1000
);
});
let
p1
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
let
success
=
true
setTimeout
(()
=>
{
if
(
success
)
{
resolve
(
null
);
}
else
{
reject
(
new
Error
(
"this is promise 1 reject reasion"
))
}
},
2000
);
});
let
p2
=
new
Promise
<
SyntaxResult
|
null
>
((
resolve
,
reject
)
=>
{
let
success
=
false
setTimeout
(()
=>
{
if
(
success
)
{
resolve
(
null
);
}
else
{
// reject(new Error("this is promise 2 reject reasion"))
reject
(
null
)
}
},
2500
);
});
// test for any
let
pt
=
Promise
.
any
([
p0
,
p1
,
p2
]);
pt
.
then
(
(
res
)
=>
{
console
.
log
(
"promise.any test success"
,
res
)
})
.
catch
(
(
error
:
any
|
null
)
=>
{
if
(
error
instanceof
UTSPromiseAggregateError
)
{
let
err
=
error
as
UTSPromiseAggregateError
console
.
log
(
err
.
name
,
err
.
message
,
err
.
errors
);
}
else
{
console
.
log
(
error
);
}
})
// test for allSettled
Promise
.
allSettled
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
res
.
forEach
((
item
,
index
)
=>
{
if
(
item
instanceof
UTSPromiseFulfilledResult
<
SyntaxResult
|
null
>
)
{
let
item0
=
item
as
UTSPromiseFulfilledResult
console
.
log
(
item0
.
value
,
"UTSPromiseFulfilledResult value"
)
}
else
if
(
item
instanceof
UTSPromiseRejectedResult
<
SyntaxResult
|
null
>
)
{
let
item0
=
item
as
UTSPromiseRejectedResult
console
.
log
(
item0
.
reason
,
"UTSPromiseRejectedResult reason"
)
}
})
})
.
catch
((
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"rejected test for promise.allSettled"
)
})
// test for all
Promise
.
all
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
console
.
log
(
res
,
res
.
count
)
})
.
catch
(
(
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"rejected test for promise.all"
)
})
// test for race
Promise
.
race
([
p0
,
p1
,
p2
])
.
then
((
res
)
=>
{
console
.
log
(
res
,
"resolved test for promise.race"
);
})
.
catch
((
error
:
any
|
null
)
=>
{
console
.
log
(
error
,
"catch test for promise.race"
)
})
}
// #endif
// #endif
export
class
SetterTest
{
private
_nickName
:
string
=
''
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录