Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
8c1900b9
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
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看板
提交
8c1900b9
编写于
1月 25, 2024
作者:
W
wangjinxin613
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(watch-effect):调整示例兼容 safari
上级
3fd967a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
127 addition
and
126 deletion
+127
-126
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
...position-api/reactivity/watch-effect/watch-effect.test.js
+127
-126
未找到文件。
pages/composition-api/reactivity/watch-effect/watch-effect.test.js
浏览文件 @
8c1900b9
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-effect/watch-effect
'
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/watch-effect/watch-effect
'
describe
(
'
watchEffect
'
,
()
=>
{
describe
(
'
watchEffect
'
,
()
=>
{
let
page
=
null
const
isSafari
=
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
safari
'
)
>
-
1
beforeAll
(
async
()
=>
{
let
page
=
null
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
beforeAll
(
async
()
=>
{
await
page
.
waitFor
(
'
view
'
)
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
})
await
page
.
waitFor
(
'
view
'
)
it
(
'
count
'
,
async
()
=>
{
})
const
count
=
await
page
.
$
(
'
#count
'
)
it
(
'
count
'
,
async
()
=>
{
expect
(
await
count
.
text
()).
toBe
(
'
count: 0
'
)
const
count
=
await
page
.
$
(
'
#count
'
)
expect
(
await
count
.
text
()).
toBe
(
'
count: 0
'
)
// watch
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
// watch
expect
(
await
watchCountRes
.
text
()).
toBe
(
const
watchCountRes
=
await
page
.
$
(
'
#watch-count-res
'
)
'
watch count result: count: 0, count ref text (flush sync): count: 0
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
// track
'
watch count result: count: 0, count ref text (flush sync): count: 0
'
)
const
watchCountTrackNum
=
await
page
.
$
(
'
#watch-count-track-num
'
)
// track
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
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
'
)
// trigger
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
const
watchCountTriggerNum
=
await
page
.
$
(
'
#watch-count-trigger-num
'
)
const
watchCountCleanupRes
=
await
page
.
$
(
'
#watch-count-cleanup-res
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 1
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 0
'
)
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
'
)
// watch count and obj.num
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 0, obj.num: 0
'
)
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
()
const
incrementBtn
=
await
page
.
$
(
'
.increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
expect
(
await
count
.
text
()).
toBe
(
'
count: 1
'
)
'
watch count result: count: 1, count ref text (flush sync): count: 0
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
'
watch count result: count: 1, count ref text (flush sync): count: 0
'
)
expect
(
await
watchCountTriggerNum
.
text
()).
toBe
(
'
watch count trigger number: 2
'
)
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 1
'
)
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
'
)
expect
(
await
watchCountAndObjNumRes
.
text
()).
toBe
(
'
watch count and obj.num result: count: 1, obj.num: 0
'
)
await
incrementBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
expect
(
await
count
.
text
()).
toBe
(
'
count: 2
'
)
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
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
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
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
'
)
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
'
)
// stop watch
await
stopWatchCountBtn
.
tap
()
const
stopWatchCountBtn
=
await
page
.
$
(
'
.stop-watch-count-btn
'
)
await
stopWatchCountBtn
.
tap
()
await
incrementBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
expect
(
await
count
.
text
()).
toBe
(
'
count: 3
'
)
'
watch count result: count: 2, count ref text (flush sync): count: 1
'
)
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
watchCountTrackNum
.
text
()).
toBe
(
'
watch count track number: 3
'
)
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup result: watch count cleanup: 2
'
)
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
'
)
})
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
'
)
it
(
'
obj
'
,
async
()
=>
{
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 0
'
)
const
objStr
=
await
page
.
$
(
'
#obj-str
'
)
const
objNum
=
await
page
.
$
(
'
#obj-num
'
)
expect
(
await
objStr
.
text
()).
toBe
(
'
obj.str: num: 0
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 0
'
)
const
objNum
=
await
page
.
$
(
'
#obj-num
'
)
const
objBool
=
await
page
.
$
(
'
#obj-bool
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 0
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: false
'
)
const
objBool
=
await
page
.
$
(
'
#obj-bool
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: false
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0]
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
isSafari
?
'
obj.arr: [ 0]
'
:
'
obj.arr: [0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
expect
(
await
watchObjRes
.
text
()).
toBe
(
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
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
(
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
'
watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
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
(
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
'
watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0
'
)
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
(
const
watchObjBoolRes
=
await
page
.
$
(
'
#watch-obj-bool-res
'
)
'
watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false
'
)
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
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
()
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
objStr
.
text
()).
toBe
(
'
obj.str: num: 1
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: true
'
)
expect
(
await
objNum
.
text
()).
toBe
(
'
obj.num: 1
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
obj.arr: [0,1]
'
)
expect
(
await
objBool
.
text
()).
toBe
(
'
obj.bool: true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
isSafari
?
'
obj.arr: [ 0, 1]
'
:
'
obj.arr: [0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
'
watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
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
(
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
'
watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
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
watchObjStrRes
.
text
()).
toBe
(
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0
'
)
'
watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true
'
)
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]
'
)
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
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录