Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
d507a19b
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
361
Star
3
Fork
8
代码
文件
提交
分支
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看板
提交
d507a19b
编写于
7个月前
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(reactivity watch): 优化 watch 相关测试
上级
886f8c9e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
28 addition
and
61 deletion
+28
-61
pages/reactivity/core/watch-post-effect/watch-post-effect.test.js
...activity/core/watch-post-effect/watch-post-effect.test.js
+4
-20
pages/reactivity/core/watch-post-effect/watch-post-effect.uvue
.../reactivity/core/watch-post-effect/watch-post-effect.uvue
+1
-1
pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js
...activity/core/watch-sync-effect/watch-sync-effect.test.js
+3
-19
pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue
.../reactivity/core/watch-sync-effect/watch-sync-effect.uvue
+1
-1
pages/reactivity/core/watch/watch-options.test.js
pages/reactivity/core/watch/watch-options.test.js
+14
-19
pages/reactivity/core/watch/watch-options.uvue
pages/reactivity/core/watch/watch-options.uvue
+5
-1
未找到文件。
pages/reactivity/core/watch-post-effect/watch-post-effect.test.js
浏览文件 @
d507a19b
...
...
@@ -6,7 +6,7 @@ describe('watchPostEffect', () => {
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIos
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
...
...
@@ -113,16 +113,8 @@ describe('watchPostEffect', () => {
expect
(
await
objArr
.
text
()).
toBe
(
'
[0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
// TODO web端和安卓端JSON.stringify对属性的排序不一致
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
str: num: 0, obj.str ref text: num: 0
'
)
...
...
@@ -142,15 +134,7 @@ describe('watchPostEffect', () => {
expect
(
await
objBool
.
text
()).
toBe
(
'
true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
[0,1]
'
)
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
str: num: 1, obj.str ref text: num: 1
'
)
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch-post-effect/watch-post-effect.uvue
浏览文件 @
d507a19b
...
...
@@ -127,7 +127,7 @@
const watchObjRes = ref('')
watchPostEffect(() => {
watchObjRes.value = `obj:
${JSON.stringify(obj)
}`
watchObjRes.value = `obj:
{"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}
}`
})
const objStrRef = ref<UniTextElement | null>(null)
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch-sync-effect/watch-sync-effect.test.js
浏览文件 @
d507a19b
...
...
@@ -6,7 +6,7 @@ describe('watchSyncEffect', () => {
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIos
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
...
...
@@ -111,15 +111,7 @@ describe('watchSyncEffect', () => {
expect
(
await
objArr
.
text
()).
toBe
(
'
[0]
'
)
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
isWeb
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}
'
)
const
watchObjStrRes
=
await
page
.
$
(
'
#watch-obj-str-res
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
...
...
@@ -140,15 +132,7 @@ describe('watchSyncEffect', () => {
expect
(
await
objBool
.
text
()).
toBe
(
'
true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
[0,1]
'
)
if
(
isWeb
||
isIos
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
else
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
str: num: 1, obj.str ref text: num: 0
'
)
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch-sync-effect/watch-sync-effect.uvue
浏览文件 @
d507a19b
...
...
@@ -127,7 +127,7 @@
const watchObjRes = ref('')
watchSyncEffect(() => {
watchObjRes.value = `obj:
${JSON.stringify(obj)
}`
watchObjRes.value = `obj:
{"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}
}`
})
const objStrRef = ref<UniTextElement | null>(null)
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch/watch-options.test.js
浏览文件 @
d507a19b
...
...
@@ -36,7 +36,7 @@ describe('watch', () => {
expect
(
await
count
.
text
()).
toBe
(
'
1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
count: 1, prevCount: 0, count ref text (flush sync): 0
'
)
`count: 1, prevCount: 0, count ref text (flush sync):
${
isWeb
?
'
null
'
:
'
0
'
}
`
)
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
1
'
)
...
...
@@ -49,12 +49,13 @@ describe('watch', () => {
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
2
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
count: 2, prevCount: 1, count ref text (flush sync): 1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
`count: 2, prevCount: 1, count ref text (flush sync):
${
isWeb
?
'
null
'
:
'
1
'
}
`
)
if
(
isAndroid
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
1
'
)
}
if
(
isIos
||
isWeb
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
...
...
@@ -74,12 +75,12 @@ describe('watch', () => {
await
incrementBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
3
'
)
if
(
isApp
)
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
count: 3, prevCount: 2, count ref text (flush sync): 2
'
)
}
if
(
isWeb
)
{
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
count: 2, prevCount: 1, count ref text (flush sync):
1
'
)
expect
(
await
watchCountRes
.
text
()).
toBe
(
'
count: 2, prevCount: 1, count ref text (flush sync):
null
'
)
}
if
(
isAndroid
)
{
...
...
@@ -91,7 +92,7 @@ describe('watch', () => {
if
(
isWeb
)
{
expect
(
await
watchCountTrackNum
.
text
()).
toBe
(
'
3
'
)
}
expect
(
await
watchCountCleanupRes
.
text
()).
toBe
(
'
watch count cleanup: 2
'
)
})
...
...
@@ -108,7 +109,7 @@ describe('watch', () => {
const
watchObjRes
=
await
page
.
$
(
'
#watch-obj-res
'
)
if
(
isAndroid
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"
arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"
}
'
'
obj: {"
num":0,"str":"num: 0","bool":false,"arr":[0]}, prevObj: {"num":0,"str":"num: 0","bool":false,"arr":[0]
}
'
)
}
if
(
isIos
||
isWeb
)
{
...
...
@@ -136,23 +137,17 @@ describe('watch', () => {
expect
(
await
objBool
.
text
()).
toBe
(
'
true
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
[0,1]
'
)
if
(
isAndroid
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}
'
)
}
if
(
isIos
||
isWeb
)
{
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
}
expect
(
await
watchObjRes
.
text
()).
toBe
(
'
obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}
'
)
expect
(
await
watchObjStrRes
.
text
()).
toBe
(
'
str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): num: 0
'
)
`str: num: 1, prevStr: num: 0, obj.str ref text (flush pre):
${
isWeb
?
'
null
'
:
'
num: 0
'
}
`
)
expect
(
await
watchObjStrTriggerNum
.
text
()).
toBe
(
'
0
'
)
expect
(
await
watchObjBoolRes
.
text
()).
toBe
(
'
bool: true, prevBool: false, obj.bool ref text (flush post): true
'
`bool: true, prevBool: false, obj.bool ref text (flush post):
${
isWeb
?
'
null
'
:
'
true
'
}
`
)
expect
(
await
watchObjArrRes
.
text
()).
toBe
(
'
arr: [0,1], prevArr: [0,1]
'
)
})
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/watch/watch-options.uvue
浏览文件 @
d507a19b
...
...
@@ -156,7 +156,11 @@
watch: {
obj: {
handler(obj : Obj, prevObj ?: Obj) {
this.watchObjRes = `obj: ${JSON.stringify(obj)}, prevObj: ${JSON.stringify(prevObj)}`
if (prevObj === null) {
this.watchObjRes = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}, prevObj: ${JSON.stringify(prevObj)}`
} else {
this.watchObjRes = `obj: {"num":${obj.num},"str":"${obj.str}","bool":${obj.bool},"arr":${JSON.stringify(obj.arr)}}, prevObj: {"num":${prevObj?.num},"str":"${prevObj?.str}","bool":${prevObj?.bool},"arr":${JSON.stringify(prevObj?.arr)}}`
}
},
// immediate: true 第一次触发, 旧值应该是 undefined, 现在 app 是初始值
immediate: true,
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部