Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
1a351bae
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
349
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1a351bae
编写于
3月 22, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 调整 composition api watch 相关测试
上级
f99056ba
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
273 addition
and
159 deletion
+273
-159
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
...position-api/reactivity/watch-effect/watch-effect.test.js
+154
-126
pages/composition-api/reactivity/watch-effect/watch-effect.uvue
...composition-api/reactivity/watch-effect/watch-effect.uvue
+1
-1
pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js
...pi/reactivity/watch-post-effect/watch-post-effect.test.js
+45
-11
pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue
...n-api/reactivity/watch-post-effect/watch-post-effect.uvue
+1
-1
pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js
...pi/reactivity/watch-sync-effect/watch-sync-effect.test.js
+46
-10
pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue
...n-api/reactivity/watch-sync-effect/watch-sync-effect.uvue
+1
-1
pages/composition-api/reactivity/watch/watch.test.js
pages/composition-api/reactivity/watch/watch.test.js
+23
-8
pages/composition-api/reactivity/watch/watch.uvue
pages/composition-api/reactivity/watch/watch.uvue
+2
-1
未找到文件。
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
浏览文件 @
1a351bae
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-effect/watch-effect
'
describe
(
'
watchEffect
'
,
()
=>
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
count
'
,
async
()
=>
{
const
count
=
await
page
.
$
(
'
#count
'
)
expect
(
await
count
.
text
()).
toBe
(
'
count: 0
'
)
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 0, count ref text (flush sync): count: 0
'
)
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
// trigger
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 0
'
)
// watch count and obj.num
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 0, obj.num: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
.increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text (flush sync): count: 0
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 1, obj.num: 0
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 3
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 2, obj.num: 0
'
)
// stop watch
const
stopWatchCountBtn
=
await
page
.
$
(
'
.stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 3
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 0
'
)
})
it
(
'
obj
'
,
async
()
=>
{
const
objStr
=
await
page
.
$
(
'
#obj-str
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 0
'
)
const
objNum
=
await
page
.
$
(
'
#obj-num
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 0
'
)
const
objBool
=
await
page
.
$
(
'
#obj-bool
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: false
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
}
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0]
'
)
const
updateObjBtn
=
await
page
.
$
(
'
.update-obj-btn
'
)
await
updateObjBtn
.
tap
()
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 1
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 1
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0,1]
'
)
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 1
'
)
})
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-effect/watch-effect
'
describe
(
'
watchEffect
'
,
()
=>
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
count
'
,
async
()
=>
{
const
count
=
await
page
.
$
(
'
#count
'
)
expect
(
await
count
.
text
()).
toBe
(
'
count: 0
'
)
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 0, count ref text (flush sync): count: 0
'
)
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 11
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 6
'
)
}
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 0
'
)
// watch count and obj.num
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 0, obj.num: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
.increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text (flush sync): count: 0
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 19
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 9
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 1, obj.num: 0
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 2, obj.num: 0
'
)
// stop watch
const
stopWatchCountBtn
=
await
page
.
$
(
'
.stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 0
'
)
})
it
(
'
obj
'
,
async
()
=>
{
const
objStr
=
await
page
.
$
(
'
#obj-str
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 0
'
)
const
objNum
=
await
page
.
$
(
'
#obj-num
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 0
'
)
const
objBool
=
await
page
.
$
(
'
#obj-bool
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: false
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
}
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
// trigger
const
watchObjStrTriggerNum
=
await
page
.
$
(
'
#watch-obj-str-trigger-num
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 1
'
)
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0]
'
)
const
updateObjBtn
=
await
page
.
$
(
'
.update-obj-btn
'
)
await
updateObjBtn
.
tap
()
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 1
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 1
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 2
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0,1]
'
)
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 1
'
)
})
})
\ No newline at end of file
pages/composition-api/reactivity/watch-effect/watch-effect.uvue
浏览文件 @
1a351bae
...
...
@@ -15,7 +15,7 @@
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
<text id="watch-
count
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
<text id="watch-
obj-str
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
{{ watchObjStrTriggerNum }}</text>
<text id="obj-num" class="uni-common-mb">obj.num: {{ obj.num }}</text>
<text id="obj-bool" ref="objBoolRef" class="uni-common-mb">obj.bool: {{ obj.bool }}</text>
...
...
pages/composition-api/reactivity/watch-post-effect/watch-post-effect.test.js
浏览文件 @
1a351bae
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-post-effect/watch-post-effect
'
describe
(
'
watchPostEffect
'
,
()
=>
{
describe
(
'
watchPostEffect
'
,
()
=>
{
const
isWeb
=
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
@@ -17,11 +18,15 @@ describe('watchPostEffect', () => {
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 8
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
// trigger
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 0
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
// TODO web端自动化测试text方法应使用textContent获取内容来保留空格,目前text方法未保留首尾空格
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
isWeb
?
'
watch count cleanup result:
'
:
...
...
@@ -37,8 +42,15 @@ describe('watchPostEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text: count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 16
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 6
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 1, obj.num: 0
'
)
...
...
@@ -48,8 +60,15 @@ describe('watchPostEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: count: 2
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 24
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 9
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 2, obj.num: 0
'
)
...
...
@@ -63,8 +82,15 @@ describe('watchPostEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: count: 2
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 24
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 9
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 0
'
)
...
...
@@ -94,6 +120,11 @@ describe('watchPostEffect', () => {
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text: obj.str: num: 0
'
)
// trigger
const
watchObjStrTriggerNum
=
await
page
.
$
(
'
#watch-obj-str-trigger-num
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 0
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0]
'
)
...
...
@@ -117,6 +148,9 @@ describe('watchPostEffect', () => {
}
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 1
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0,1]
'
)
...
...
pages/composition-api/reactivity/watch-post-effect/watch-post-effect.uvue
浏览文件 @
1a351bae
...
...
@@ -14,7 +14,7 @@
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
<text id="watch-
count
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
<text id="watch-
obj-str
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
{{ watchObjStrTriggerNum }}</text>
<text id="obj-num" class="uni-common-mb">obj.num: {{ obj.num }}</text>
<text id="obj-bool" ref="objBoolRef" class="uni-common-mb">obj.bool: {{ obj.bool }}</text>
...
...
pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.test.js
浏览文件 @
1a351bae
...
...
@@ -17,11 +17,15 @@ describe('watchSyncEffect', () => {
// track
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 11
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 6
'
)
}
// trigger
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 0
'
)
...
...
@@ -35,8 +39,16 @@ describe('watchSyncEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, count ref text: count: 0
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 19
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 9
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 1, obj.num: 0
'
)
...
...
@@ -46,8 +58,16 @@ describe('watchSyncEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 3
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 2, obj.num: 0
'
)
...
...
@@ -61,8 +81,16 @@ describe('watchSyncEffect', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, count ref text: count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 3
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
IOS
'
))
{
// TODO: 确认 IOS 的差异是否正常
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 27
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 12
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 3, obj.num: 0
'
)
...
...
@@ -92,6 +120,11 @@ describe('watchSyncEffect', () => {
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 0, obj.str ref text: obj.str: num: 0
'
)
// trigger
const
watchObjStrTriggerNum
=
await
page
.
$
(
'
#watch-obj-str-trigger-num
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 1
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0]
'
)
...
...
@@ -116,6 +149,9 @@ describe('watchSyncEffect', () => {
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 0
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 2
'
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
watch obj.arr result: arr: [0,1]
'
)
const
watchCountAndObjNumRes
=
await
page
.
$
(
'
#watch-count-obj-num-res
'
)
...
...
pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect.uvue
浏览文件 @
1a351bae
...
...
@@ -15,7 +15,7 @@
stop watch count
</button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
<text id="watch-
count
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
<text id="watch-
obj-str
-trigger-num" class="uni-common-mb">watch obj.str trigger number:
{{ watchObjStrTriggerNum }}</text>
<text id="obj-num" class="uni-common-mb">obj.num: {{ obj.num }}</text>
<text id="obj-bool" ref="objBoolRef" class="uni-common-mb">obj.bool: {{ obj.bool }}</text>
...
...
pages/composition-api/reactivity/watch/watch.test.js
浏览文件 @
1a351bae
...
...
@@ -18,9 +18,6 @@ describe('watch', () => {
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
// trigger
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 0
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
((
await
watchCountCleanupRes
.
text
()).
trim
()).
toBe
(
'
watch count cleanup result:
'
)
...
...
@@ -36,8 +33,11 @@ describe('watch', () => {
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 1, prevCount: 0, count ref text (flush sync): count: 0
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 4
'
)
}
expect
((
await
watchCountCleanupRes
.
text
()).
trim
()).
toBe
(
'
watch count cleanup result:
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
...
...
@@ -48,8 +48,12 @@ describe('watch', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 6
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
...
...
@@ -66,8 +70,12 @@ describe('watch', () => {
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 2
'
)
}
else
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 6
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
...
...
@@ -96,6 +104,11 @@ describe('watch', () => {
}
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
((
await
watchObjStrRes
.
text
()).
trim
()).
toBe
(
'
watch obj.str result:
'
)
// trigger
const
watchObjStrTriggerNum
=
await
page
.
$
(
'
#watch-obj-str-trigger-num
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 0
'
)
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
expect
((
await
watchObjBoolRes
.
text
()).
trim
()).
toBe
(
'
watch obj.bool result:
'
)
const
watchObjArrRes
=
await
page
.
$
(
'
#watch-obj-arr-res
'
)
...
...
@@ -122,6 +135,8 @@ describe('watch', () => {
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
watch obj.str trigger number: 1
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): obj.bool: true
'
)
...
...
pages/composition-api/reactivity/watch/watch.uvue
浏览文件 @
1a351bae
...
...
@@ -70,7 +70,8 @@
watchCountTrackNum.value++
}
}
// TODO: vue>3.4.15 开始 onTrack onTrigger 同时存在修改响应式数据时,会报错 Maximum call stack size exceeded
// TODO: vue>3.4.15 开始 监听函数、onTrack、onTrigger 同时存在修改响应式数据时,会报错 Maximum call stack size exceeded
// 所以将 onTrack 与 onTrigger 调整到两个 watch 里
})
const triggerStopWatchCount = () => stopWatchCount()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录