Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
9bc6c789
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
402
Star
3
Fork
10
代码
文件
提交
分支
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看板
提交
9bc6c789
编写于
11月 13, 2023
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(watch): 增加 Array 测试,含子组件
上级
2626a1dd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
181 addition
and
0 deletion
+181
-0
pages.json
pages.json
+6
-0
pages/component-instance/watch-function/watch-array-child.uvue
.../component-instance/watch-function/watch-array-child.uvue
+42
-0
pages/component-instance/watch-function/watch-array.test.js
pages/component-instance/watch-function/watch-array.test.js
+67
-0
pages/component-instance/watch-function/watch-array.uvue
pages/component-instance/watch-function/watch-array.uvue
+61
-0
pages/index.uvue
pages/index.uvue
+5
-0
未找到文件。
pages.json
浏览文件 @
9bc6c789
...
...
@@ -174,6 +174,12 @@
"navigationBarTitleText"
:
"$watch()"
}
},
{
"path"
:
"pages/component-instance/watch-function/watch-array"
,
"style"
:
{
"navigationBarTitleText"
:
"watch-array"
}
},
{
"path"
:
"pages/component-instance/emit-function/emit-function"
,
"style"
:
{
...
...
pages/component-instance/watch-function/watch-array-child.uvue
0 → 100644
浏览文件 @
9bc6c789
<template>
<view>
<view v-for="(item, index) in list">
<text class="data-item-text">{{JSON.stringify(item)}}</text>
<!-- TODO 暂不支持 for UTSJSONObject -->
<!-- <view v-for="(value, key) in item">
<text class="k">{{key}}</text>
<text class="v">{{value}}</text>
</view> -->
</view>
<view>
<text class="watch-count">{{watchCount}}</text>
</view>
</view>
</template>
<script>
import { PropType } from 'vue'
export default {
name: 'ArrayDeep',
props: {
list: {
type: Array as PropType<Array<UTSJSONObject>>,
default: [] as Array<UTSJSONObject>
},
},
data() {
return {
watchCount: 0
}
},
watch: {
list: {
handler(newValue : Array<UTSJSONObject>) {
this.watchCount++
},
deep: true,
immediate: true
}
}
}
</script>
\ No newline at end of file
pages/component-instance/watch-function/watch-array.test.js
0 → 100644
浏览文件 @
9bc6c789
const
PAGE_PATH
=
'
/pages/component-instance/watch-function/watch-array
'
describe
(
'
watch
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
change
'
,
async
()
=>
{
// immediate count = 1
await
validateCount
(
page
,
1
)
const
btnChangeData1
=
await
page
.
$
(
'
.change-data1
'
)
await
btnChangeData1
.
tap
()
await
page
.
waitFor
(
100
)
// count = 1, 暂不支持 deep
await
validateCount
(
page
,
1
)
// 验证数据正确性
await
validateData1
(
page
,
1
,
2
)
const
btnChangeData2
=
await
page
.
$
(
'
.change-data2
'
)
await
btnChangeData2
.
tap
()
await
page
.
waitFor
(
100
)
// count = 2,重新赋值触发
await
validateCount
(
page
,
2
)
// 验证数据正确性
await
validateData2
(
page
,
3
,
4
)
})
})
async
function
validateCount
(
page
,
count
)
{
// page
const
count_text
=
await
page
.
$
(
'
.watch-count
'
)
expect
(
await
count_text
.
text
()).
toBe
(
count
+
''
)
// page.child
const
count_child
=
await
page
.
$
(
'
.watch-array-child
'
)
const
count_child_text
=
await
count_child
.
$
(
'
.watch-count
'
)
expect
(
await
count_child_text
.
text
()).
toBe
(
count
+
''
)
}
async
function
validateData1
(
page
,
value1
,
value2
)
{
const
page_text
=
await
page
.
$
(
'
.data-item-text
'
)
const
page_json
=
JSON
.
parse
(
await
page_text
.
text
())
expect
(
page_json
.
a
).
toBe
(
value1
)
expect
(
page_json
.
b
).
toBe
(
value2
)
const
child
=
await
page
.
$
(
'
.watch-array-child
'
)
const
child_text
=
await
child
.
$
(
'
.data-item-text
'
)
const
child_json
=
JSON
.
parse
(
await
child_text
.
text
())
expect
(
child_json
.
a
).
toBe
(
value1
)
expect
(
child_json
.
b
).
toBe
(
value2
)
}
async
function
validateData2
(
page
,
value1
,
value2
)
{
const
page_text
=
await
page
.
$
(
'
.data-item-text
'
)
const
page_json
=
JSON
.
parse
(
await
page_text
.
text
())
expect
(
page_json
.
c
).
toBe
(
value1
)
expect
(
page_json
.
d
).
toBe
(
value2
)
const
child
=
await
page
.
$
(
'
.watch-array-child
'
)
const
child_text
=
await
child
.
$
(
'
.data-item-text
'
)
const
child_json
=
JSON
.
parse
(
await
child_text
.
text
())
expect
(
child_json
.
c
).
toBe
(
value1
)
expect
(
child_json
.
d
).
toBe
(
value2
)
}
\ No newline at end of file
pages/component-instance/watch-function/watch-array.uvue
0 → 100644
浏览文件 @
9bc6c789
<template>
<view>
<view v-for="(item, index) in dataList">
<text class="data-item-text">{{JSON.stringify(item)}}</text>
<!-- TODO 暂不支持 for UTSJSONObject -->
<!-- <view v-for="(value, key) in item">
<text class="k">{{key}}</text>
<text class="v">{{value}}</text>
</view> -->
</view>
<view>
<text class="watch-count">{{watchCount}}</text>
</view>
<view>
<text>Watch array in component</text>
</view>
<watch-array-child class="watch-array-child" :list="dataList"></watch-array-child>
<button class="change-data1" @click="changeData1">changeData1(push)</button>
<button class="change-data2" @click="changeData2">changeData2(allocate)</button>
</view>
</template>
<script>
import WatchArrayChild from './watch-array-child.uvue'
export default {
components: {
WatchArrayChild
},
data() {
return {
dataList: [] as Array<UTSJSONObject>,
watchCount: 0
}
},
watch: {
dataList: {
handler(newValue : Array<UTSJSONObject>) {
this.watchCount++
},
deep: true,
immediate: true
}
},
methods: {
changeData1() {
let item = {
"a": 1,
"b": 2
}
this.dataList.push(item)
},
changeData2() {
let list = [{
"c": 3,
"d": 4
}] as Array<UTSJSONObject>
this.dataList = list
}
}
}
</script>
\ No newline at end of file
pages/index.uvue
浏览文件 @
9bc6c789
...
...
@@ -272,6 +272,11 @@
url: 'watch-function',
enable: true,
},
{
name: 'watch-array',
url: 'watch-function/watch-array',
enable: true,
},
{
name: '$emit',
url: 'emit-function',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录